我已经为这个错误工作了一个星期,但搜索后仍然无法解决。错误是:
远程服务器返回意外响应:(400) 错误请求。
我尝试通过 WCF 从 Windows 手机应用程序保存图像,我知道我需要设置MaxReceivedMessageSize
高于默认值!我已经尝试了一切,但没有运气!
我的web.config
文件(wcf 服务)
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1"
maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647"
maxBufferPoolSize="2147483647"
hostNameComparisonMode="StrongWildcard"
receiveTimeout="00:10:10"
sendTimeout="00:10:00"
openTimeout="00:10:00"
closeTimeout="00:10:00"
transferMode="Buffered"
messageEncoding="Text"
textEncoding="utf-8"
bypassProxyOnLocal="false"
useDefaultWebProxy="true" >
<readerQuotas
maxDepth="2147483647"
maxStringContentLength="2147483646"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="Service1" behaviorConfiguration="Service1Behavior">
<endpoint
address=""
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1"
contract="IService1" />
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"
/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Service1Behavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>
在我的 Windows 手机应用程序上只有ServiceReferences.ClientConfig
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:1772/Service1.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1"
contract="ServiceReference1.IService1"
name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
</configuration>
我也尝试在代码中设置绑定:
BasicHttpBinding binding = new BasicHttpBinding();
binding.MaxReceivedMessageSize = 2147483647;
binding.MaxBufferSize = 2147483647;
EndpointAddress endpointAddress = new EndpointAddress("http://localhost:1772/Service1.svc");
Service1Client proxy = new Service1Client(binding, endpointAddress);
我真的不知道如何解决这个问题......看起来服务器没有使用我的 web.config 文件???如果是这种情况,我该如何更新?