モバイルで使用する JSON 情報を返す C# WebService セットアップがあります。「HTTP エラー 502 (不正なゲートウェイ): ゲートウェイまたはプロキシ サーバーがアップストリーム サーバーから無効な応答を受け取りました」をスローする呼び出しの 1 つを除いて、すべて正常に動作しています。
呼び出しが返すデータを増やしたときにエラーが発生しました。データは、サーバーにある JSON ファイルから読み取られます。このデータ ファイルのサイズは、以前は 1,324,859 バイトでしたが、正常に動作しました (現在も正常に動作しています)。新しいデータ ファイルは 1,563,570 バイトで、これが失敗しています。
1 回の呼び出しで返すことができる量に対して、何らかのデフォルトの制限に達したことは明らかですが、この制限を増やす方法を理解することはできません。グーグルはmaxJsonLengthを設定する方向を指していますが、これは何の効果もないようです。
以下は、WebService とさらに重要な私の web.config の詳細なコードです。つまり、VS2010 での実行中は呼び出しが正常に機能していますが、サーバー (IIS 7.5 を実行している GearHost) では失敗しています。
私は IIS の構成/セットアップの初心者なので、どんな助けも大歓迎です。
[ServiceContract]
public interface IMyService
{
[OperationContract]
[WebInvoke(Method = "GET", UriTemplate = "/GetItems", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
Item[] GetItems();
}
public class MyService : IMyService
{
public Item[] GetItems()
{
var result = ReadDataFile<List<Item>>(DataType.Items);
return result == null ? null : result.ToArray();
}
}
これまでに非常に多くの設定を試したので、ここに何が必要で、何が必要でないかさえわかりません...
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere" />
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" />
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" />
<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" />
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>
<system.web>
<customErrors mode="On"/>
<compilation debug="true" targetFramework="4.0" />
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<add name="NoCacheProfile" noStore="true" duration="0" varyByParam="none" enabled="true"/>
</outputCacheProfiles>
</outputCacheSettings>
</caching>
</system.web>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="StreamedRequestWebBinding"
bypassProxyOnLocal="true"
useDefaultWebProxy="false"
hostNameComparisonMode="WeakWildcard"
sendTimeout="10:15:00"
openTimeout="10:15:00"
receiveTimeout="10:15:00"
maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647"
maxBufferPoolSize="2147483647"
transferMode="StreamedRequest">
<readerQuotas maxArrayLength="2147483647"
maxStringContentLength="2147483647" />
</binding>
</webHttpBinding>
</bindings>
<services>
<service name="JSON_WebService.WoWService" behaviorConfiguration="ServiceBehaviour">
<endpoint address ="" binding="webHttpBinding" bindingConfiguration="StreamedRequestWebBinding" contract="JSON_WebService.IWoWService" behaviorConfiguration="web">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="50000000"/>
</webServices>
</scripting>
</system.web.extensions>
</configuration>