2016-08-04 7 views
0

私はbasicHttpBindingプロトコルをWCFに使用しています。WCFリモートサーバーが予期しない応答を返しました:(400)不正な要求

大きいClass<T>(問題ありません)が届きます。

しかし、私はClass<T>は私が

例外がスローされ、このエラーが出る大送る: 'System.ServiceModel.ProtocolException' を にSystem.ServiceModel.Internals.dll

追加情報:リモートサーバーが返さ予想外の レスポンス:(400)Bad Request。

私のサーバ設定が

<?xml version="1.0"?> 
<configuration> 
    <system.diagnostics> 
    <sources> 
     <source propagateActivity="true" 
       name="System.ServiceModel" 
       switchValue="Warning,ActivityTracing"> 
     <listeners> 
      <add type="System.Diagnostics.DefaultTraceListener" 
       name="Default"> 
      <filter type="" /> 
      </add> 
      <add name="ServiceModelTraceListener"> 
      <filter type="" /> 
      </add> 
     </listeners> 
     </source> 
     <source name="System.ServiceModel.MessageLogging" 
       switchValue="Information, ActivityTracing"> 
     <listeners> 
      <add type="System.Diagnostics.DefaultTraceListener" 
       name="Default"> 
      <filter type="" /> 
      </add> 
      <add name="ServiceModelMessageLoggingListener"> 
      <filter type="" /> 
      </add> 
     </listeners> 
     </source> 
    </sources> 
    <sharedListeners> 
     <add initializeData="d:\tourism\tourism\server\service\deltaservicewcf\web_messages.svclog" 
     type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
     name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp"> 
     <filter type="" /> 
     </add> 
     <add initializeData="d:\tourism\tourism\server\service\deltaservicewcf\web_tracelog.svclog" 
     type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
     name="ServiceModelTraceListener" traceOutputOptions="Timestamp"> 
     <filter type="" /> 
     </add> 
    </sharedListeners> 
    <trace autoflush="true" /> 
    </system.diagnostics> 
    <system.serviceModel> 
    <diagnostics wmiProviderEnabled="false"> 
     <messageLogging logEntireMessage="true" logMalformedMessages="true" 
     logMessagesAtServiceLevel="false" logMessagesAtTransportLevel="true" /> 
    </diagnostics> 
    <bindings> 
     <basicHttpBinding> 
     <binding name="NewBinding0" closeTimeout="01:01:00" openTimeout="01:01:00" 
      receiveTimeout="01:10:00" sendTimeout="01:01:00" maxBufferPoolSize="2147483647" 
      maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" 
      transferMode="Streamed"> 
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 
      maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
     </binding> 
     </basicHttpBinding> 
    </bindings> 
    <services> 
     <service behaviorConfiguration="myHttpBindingBihaviour" name="DeltaServiceWCF.DeltaService1"> 
     <endpoint behaviorConfiguration="myHttpBindingEndPointBihaviour" 
      binding="basicHttpBinding" bindingConfiguration="" name="" contract="DeltaServiceWCF.IDeltaService1" 
      isSystemEndpoint="false" /> 
     <host> 
      <timeouts closeTimeout="01:00:10" openTimeout="01:01:00" /> 
     </host> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="myHttpBindingBihaviour"> 
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
      <serviceTimeouts transactionTimeout="01:00:01" /> 
      <dataContractSerializer ignoreExtensionDataObject="true" maxItemsInObjectGraph="2147483647"/> 
      <serviceThrottling maxConcurrentCalls="2000" maxConcurrentSessions="1000" maxConcurrentInstances="1000" /> 
     </behavior> 
     </serviceBehaviors> 
     <endpointBehaviors> 
     <behavior name="myHttpBindingEndPointBihaviour" > 
      <dataContractSerializer ignoreExtensionDataObject="true" maxItemsInObjectGraph="2147483647"/> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors> 
    <!--<protocolMapping> 
     <add binding="basicHttpsBinding" scheme="https" /> 
    </protocolMapping>--> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" 
     multipleSiteBindingsEnabled="true" /> 
    <standardEndpoints> 
     <webHttpEndpoint> 
     <standardEndpoint name="" maxBufferSize="2147483647" maxBufferPoolSize="4194304" 
      maxReceivedMessageSize="2147483647" helpEnabled="true" automaticFormatSelectionEnabled="true" 
      crossDomainScriptAccessEnabled="true"> 
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 
      maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
     </standardEndpoint> 
     </webHttpEndpoint> 
    </standardEndpoints> 

    </system.serviceModel> 
    <system.web> 
    <httpRuntime maxRequestLength="2147483647" maxQueryStringLength="2097151" maxUrlLength="2097151" maxWaitChangeNotification="2147483647" requestValidationMode="4.0" executionTimeout="110000" targetFramework="4.5"/> 
    <compilation debug="true"/> 
    <customErrors mode="Off"/> 
    </system.web> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    <!-- 
     To browse web app root directory during debugging, set the value below to true. 
     Set to false before deployment to avoid disclosing web app folder information. 
     --> 
    <directoryBrowse enabled="true"/> 

    </system.webServer> 

    <!--<system.web.extensions> 
    <scripting> 
     <webServices> 
     <authenticationService enabled="true" 
      requireSSL="false" /> 
     </webServices> 
    </scripting> 
    </system.web.extensions>--> 
</configuration> 

私のクライアントコードは、あなたの定義されたbasicHttpBindingを割り当てることはありませんので、あなたはあなたのサービスに大きなオブジェクトを送信することができない理由がある

public static EndpointAddress EndPoint = new EndpointAddress("http://192.168.1.102:9159/DeltaService1.svc"); 

public static BasicHttpBinding CreateBasicHttp() 
{ 

    var binding = new BasicHttpBinding(); 
    binding.MaxReceivedMessageSize = 2147483647; 
    binding.MessageEncoding = WSMessageEncoding.Text; 
    binding.ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas() 
    { 
     MaxArrayLength = 2147483647, 
     MaxStringContentLength = 2147483647, 
     MaxBytesPerRead = 2147483647, 
     MaxDepth = 2147483647, 
     MaxNameTableCharCount = 2147483647, 
    }; 
    binding.MaxBufferPoolSize = 2147483647; 
    binding.MaxBufferSize = 2147483647; 
    binding.TransferMode = TransferMode.Streamed; 
    binding.Security = new BasicHttpSecurity(); 

    binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName; 

    binding.Security.Mode = BasicHttpSecurityMode.None; 
    binding.Security.Transport = new HttpTransportSecurity(); 
    binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None; 
    binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None; 
    binding.Security.Transport.Realm = ""; 

    var timeout = new TimeSpan(1, 1, 0); 
    binding.SendTimeout = timeout; 

    binding.CloseTimeout = timeout; 
    binding.OpenTimeout = timeout; 
    binding.ReceiveTimeout = timeout; 
    binding.SendTimeout = timeout; 
    binding.TextEncoding = Encoding.UTF8; 

    ChannelFactory<IDeltaService1> factory = new ChannelFactory<IDeltaService1>(binding, EndPoint); 

    foreach (OperationDescription op in factory.Endpoint.Contract.Operations) 
    { 
     var dataContractBehavior = op.Behaviors.Find<DataContractSerializerOperationBehavior>(); 
     if (dataContractBehavior != null) 
     { 
      dataContractBehavior.IgnoreExtensionDataObject = true; 
      dataContractBehavior.MaxItemsInObjectGraph = int.MaxValue; 
     } 
    } 

    IDeltaService1 channel = factory.CreateChannel(); 

    return binding; 
} 

答えて

0

ですサービスエンドポイント

<bindings> 
    <basicHttpBinding> 
    <binding name="NewBinding0"..... 

しかし、あなたはエンドポイントを定義するときに、あなたはそれに "NewBinding0" を割り当てないでください:あなたのサービスのconfigで

、あなたが持っている

<endpoint behaviorConfiguration="myHttpBindingEndPointBihaviour" 
     binding="basicHttpBinding" bindingConfiguration="".... 

以来bindingConfiguration要素のdoesnバインド設定を指定しないと、basicHttpBindingのデフォルト値が使用されます。そのため、大きなオブジェクトを送信することができません。

は、このようなbindingConfiguration属性を経由して、あなたのエンドポイントに「NewBinding0」を割り当てます。

<endpoint behaviorConfiguration="myHttpBindingEndPointBihaviour" 
     binding="basicHttpBinding" bindingConfiguration="NewBinding0"..... 

そして、あなたのサービスは、クライアントが送信したときに、より大きなオブジェクトを受け取ることができるはずです。

+0

あなたの時間と助けてくれてありがとう。あなたは私を1年保存します。私はあなたにキスします – Arman

関連する問題