当POST一些数据时WCF错误400错误的请求

问题描述:

我的本地机器中有一个WCF服务,它的作用类似于客户端应用程序和远程数据库之间的“桥梁”。当POST一些数据时WCF错误400错误的请求

WCF服务与实体框架类一起工作,并且在获取数据时工作正常,但在发布任何内容时无法正常工作,并且收到下一条错误消息:“(400)Bad Request”。

这是我的客户端代码:

//Connect to WCF Service 
CHS_Local.ServiceFrontalClient proxy = new CHS_Local.ServiceFrontalClient(); 

//Get a "Client" class wich ClientID == 1 
CHS_Local.Client client = proxy.GetClient(1); 

//Change some stuff 
client.Name = "change someting"; 

//Send the modified class to service to update the database 
proxy.UpdateClient(client); 

这是我<system.serviceModel>标签WCF中的配置文件:

<system.serviceModel> 
    <services> 
     <service name="CentralizedHostingService.ServiceFrontal"> 
     <endpoint 
      address="" 
      binding="wsHttpBinding" 
      contract="CentralizedHostingService.IServiceFrontal"> 
      <identity> 
       <dns value="localhost" /> 
      </identity> 
     </endpoint> 
     <endpoint 
      address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     <host> 
      <baseAddresses> 
       <add baseAddress="http://localhost:8732/Design_Time_Addresses/CentralizedHostingService/Service1/" /> 
      </baseAddresses> 
     </host> 
    </service> 
    </services> 
    <behaviors> 
    <serviceBehaviors> 
     <behavior> 
      <serviceMetadata httpGetEnabled="True" /> 
     <serviceDebug includeExceptionDetailInFaults="False" /> 
     </behavior> 
    </serviceBehaviors> 
    </behaviors> 
</system.serviceModel> 

和我的客户端应用程序app.config

<system.serviceModel> 
    <bindings> 
     <wsHttpBinding> 
      <binding name="WSHttpBinding_IServiceFrontal" closeTimeout="00:01:00" 
       openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
       bypassProxyOnLocal="false" transactionFlow="false" 
       hostNameComparisonMode="StrongWildcard" 
       maxBufferPoolSize="524288" maxReceivedMessageSize="5000000" 
       messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" 
       allowCookies="false"> 
       <readerQuotas 
        maxDepth="32" maxStringContentLength="8192" 
        maxArrayLength="16384" maxBytesPerRead="4096" 
        maxNameTableCharCount="16384" /> 
       <reliableSession ordered="true" inactivityTimeout="00:10:00" 
        enabled="false" /> 
       <security mode="Message"> 
        <transport clientCredentialType="Windows" 
           proxyCredentialType="None" realm="" /> 
        <message clientCredentialType="Windows" 
          negotiateServiceCredential="true" 
          algorithmSuite="Default" /> 
       </security> 
      </binding> 
     </wsHttpBinding> 
    </bindings> 
    <client> 
     <endpoint 
      address="http://localhost:8732/Design_Time_Addresses/CentralizedHostingService/Service1/" 
      binding="wsHttpBinding" 
      bindingConfiguration="WSHttpBinding_IServiceFrontal" 
      contract="CHS_Local.IServiceFrontal" name="WSHttpBinding_IServiceFrontal"> 
      <identity> 
       <dns value="localhost" /> 
      </identity> 
     </endpoint> 
    </client> 
</system.serviceModel> 

服务接口:

[OperationContract] 
    Client GetClient(int clientID); 

    [OperationContract] 
    void UpdateClient(Client editedClient); 

在第一个例子中,虽然问题存在于请愿的权重,但我看到使用Fiddler字节发送请求只有115.903字节(〜0.11MB)。 有什么想法?

正如你所看到的是一个简单的例子,但没有工作:(

感谢您帮助!:)

+0

把你的服务interace这里 – Aliostad 2011-03-08 17:39:37

您必须设置maxReceivedMessageSizereaderQuotas(如果需要)在服务发布数据时来自客户。您的客户端配置已修改maxReceivedMessageSize,它用于从服务获取数据,但是当您向服务发送大量数据时,您还必须修改其配置。

喜欢的东西:

<system.serviceModel> 
    <bindings> 
    <wsHttpBinding> 
     <binding name="myBinding" maxReceivedMessageSize="500000" /> 
    </wsHttpBinding> 
    </bindings> 
    <services> 
    <service name="CentralizedHostingService.ServiceFrontal"> 
     <endpoint bindingConfiguration="myBinding" ... /> 
     ... 
    </service> 
    </services> 
    ... 
</system.serviceModel> 
+0

+1好斑点。 – Aliostad 2011-03-08 17:42:51

+0

尼斯拉迪斯拉夫!!!现在工作正常!!!!!谢谢:) – vfportero 2011-03-08 17:51:19

+0

我已经更新客户端和服务器的配置。但错误仍然存​​在。 – 2017-03-20 06:47:41