1

私のサーバー設定ファイル:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="500000000"></requestLimits>
      </requestFiltering>
    </security>
  </system.webServer>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="HttpEndpointBinding" receiveTimeout="00:10:30" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="524288">
          <readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647" />
          <security mode="None"/>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service   name="mobservice.ImobService">
        <endpoint address="" binding="basicHttpBinding" contract="mobservice.ImobService" bindingConfiguration="HttpEndpointBinding" name="BasicHttpBinding_MobileService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior >
          <serviceMetadata httpGetEnabled="true" httpGetUrl="" />
          <serviceDebug includeExceptionDetailInFaults="true" httpHelpPageEnabled="true" httpHelpPageUrl="" />
          <dataContractSerializer maxItemsInObjectGraph="60000000"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="">
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

私のクライアント設定ファイル:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
    <handlers>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_ImobService"  sendTimeout="00:10:30" maxBufferSize="250000000" maxBufferPoolSize="250000000" maxReceivedMessageSize="250000000">
          <readerQuotas maxDepth="4500000" maxStringContentLength="4500000" maxArrayLength="4500000" maxBytesPerRead="40960000" maxNameTableCharCount="250000000" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://anishk.india-powai.orioninc.com/mobservice/MobService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ImobService" contract="MobileService.ImobService" name="BasicHttpBinding_ImobService" />
    </client>
  </system.serviceModel>
</configuration>

サービス契約:

[OperationContract]
void InsertEmployeeData(EmployeeDetail empName);

メソッド定義:

public void InsertEmployeeData(EmployeeDetail empName)
{
    ctx.EmployeeDetails.AddObject(empName);
    ctx.SaveChanges();
}

クライアントからの呼び出し:

EmployeeDetail data = new EmployeeDetail();
data.EmployeeName = collection.Get("EmployeeName");
data.Designation = collection.Get("Designation");
data.EmailID = collection.Get("EmailID");
data.City = collection.Get("City");
data.State = collection.Get("State");
data.Country = collection.Get("Country");               
data.Photo = ConvertImage(@"E:\Anish\S6M0.png");
conn.InsertEmployeeData(data);

写真を含む EmployeeDetail オブジェクトをバイト配列として wcf サービスに渡そうとすると、例外が発生します。6kb の画像が挿入されますが、サイズが 50kb の画像は例外をスローします:

リモート サーバーが予期しない応答を返しました: (400) 不正な要求。

しかし、最大 2 mb の画像サイズを処理する必要があります。

4

1 に答える 1

0

web.configファイルでデバッグを有効にしてみてください。これにより、単なる よりも意味のあるエラー メッセージが表示されます(400) Bad Request

<configuration>タグの下に次の XML スニペットを追加します。

<system.web>
  <customErrors mode="Off"/>
  <trace enabled="true" localOnly="false"> 
  <compilation debug="true"/>
</system.web>

そしてさらに試みる。

デバッグ フラグは本番環境で使用するとセキュリティ上の脆弱性になるため、完了したら必ず削除してください。

于 2013-01-28T09:06:52.530 に答える