2016-08-04 30 views
0

Ich verwende das Protokoll basicHttpBinding für WCF.WCF Der Remote-Server hat eine unerwartete Antwort zurückgegeben: (400) Ungültige Anforderung

Ich empfange große Class<T> (kein Problem).

Aber ich sende große Class<T> ich diesen Fehler

Ausnahme geworfen: 'System.ServiceModel.ProtocolException' in System.ServiceModel.Internals.dll

Zusätzliche Informationen: Der Remote-Server zurückgegeben ein unerwartet Antwort: (400) Ungültige Anforderung.

Meine Serverkonfiguration ist

<?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> 

Mein Client-Code ist

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; 
} 

Antwort

0

Der Grund, warum Sie können ein großes Objekt in den Dienst nicht senden, weil Sie nie Ihre definiert zuweisen basicHttpBinding zu der Dienstendpunkt

In Ihrem Service Config, Sie haben:

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

Aber dann, wenn Sie den Endpunkt definieren, können Sie nicht zuordnen "NewBinding0", um es:

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

Da das bindingConfiguration Element doesn Wenn Sie keine Bindungskonfiguration angeben, werden die Standardwerte für basicHttpBinding verwendet. Aus diesem Grund können Sie keine großen Objekte senden.

Weisen Sie den „NewBinding0“ zu Ihrem Endpunkt über das bindingConfiguration Attribut wie folgt aus:

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

Und Ihre Dienstleistung sollte größere Objekte erhalten können, wenn der Kunde sie sendet.

+0

Vielen Dank für Ihre Zeit und Hilfe. Du sparst mich 1 Jahr. Ich sage dir – Arman