我在尝试访问wcf Web服务时遇到此异常。
[WebException: The remote server returned an error: (400) Bad Request.]
System.Net.HttpWebRequest.GetResponse() +5314029
System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +54
服务器绑定信息
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="wcfSmartConnect" closeTimeout="10:01:00"
maxBufferSize="104857600" maxBufferPoolSize="104857600"
maxReceivedMessageSize="104857600" openTimeout="10:01:00"
receiveTimeout="10:10:00" sendTimeout="10:01:00"
messageEncoding="Mtom" transferMode="StreamedRequest">
<readerQuotas maxDepth="104857600" maxStringContentLength="104857600"
maxArrayLength="104857600" maxBytesPerRead="104857600"
maxNameTableCharCount="104857600" />
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="WcfSmartConnect.Service1"
behaviorConfiguration="WcfSmartConnect.Service1Behavior">
<endpoint
address=""
binding="basicHttpBinding"
bindingConfiguration="wcfSmartConnect"
contract="WcfSmartConnect.IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint
address="mex"
binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfSmartConnect.Service1Behavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
客户端绑定信息
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="wcfSmartConnect" closeTimeout="10:01:00"
maxBufferSize="104857600" maxBufferPoolSize="104857600"
maxReceivedMessageSize="104857600" openTimeout="10:01:00"
receiveTimeout="10:10:00" sendTimeout="10:01:00"
messageEncoding="Mtom" transferMode="StreamedRequest">
<readerQuotas maxDepth="104857600" maxStringContentLength="104857600"
maxArrayLength="104857600" maxBytesPerRead="104857600"
maxNameTableCharCount="104857600" />
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="WSHttpBinding_IService11" closeTimeout="01:00:00"
openTimeout="01:00:00" receiveTimeout="01:00:00"
sendTimeout="01:00:00" bypassProxyOnLocal="false"
transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="1048576000" maxReceivedMessageSize="1048576000"
messageEncoding="Text" textEncoding="utf-8"
useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="104857600" maxStringContentLength="104857600"
maxArrayLength="104857600" maxBytesPerRead="1048576000"
maxNameTableCharCount="104857600" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="Windows"
proxyCredentialType="None" realm="" />
<message clientCredentialType="Windows"
negotiateServiceCredential="true" algorithmSuite="Default"
establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint name="WSHttpBinding_IService11"
address="http://abc.com/API/serv.svc"
binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IService11"
contract="SmartConnectRepublic.IService1" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint name="BasicHttpBinding_IService1"
address="http://localhost:4649/Service1.svc"
binding="basicHttpBinding"
bindingConfiguration="wcfSmartConnect"
contract="SmartConnect.IService1" />
</client>
</system.serviceModel>
答案 0 :(得分:2)
您能告诉我们您的设置吗?
<system.serviceModel>
内的所有内容都很有意义)看起来好像客户端超时等待服务器 - 这可能是因为服务器响应时间太长(如果你做了大量的数据加载);在这种情况下,您需要增加服务器和客户端的超时
或者您可能通过网络发送过大的数据包 - 在这种情况下,您可能还需要增加maxReceivedMessageSize
等的设置。
@Pinu:你想上传5 MB吗?您有transferMode = StreamRequest,这意味着您将从客户端到服务器的请求进行流式传输。
如果你传输的是5 MB,那么流式传输是个好主意 - 你用哪种方式传输这些字节?