WCF错误400错误的请求时,POST一些数据 [英] WCF Error 400 Bad Request when POST some data

查看:174
本文介绍了WCF错误400错误的请求时,POST一些数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的作品就像一个客户端应用程序和远程数据库之间的桥梁本地机器有一个WCF服务。

I have a WCF Service in my local machine that works like a "bridge" between a client application and a database in remote.

WCF服务可以与实体框架类和正常工作时,你得到的数据,但不会在张贴任何工作,我得到一个错误信息:(400)错误的请求

The WCF service works with Entity Framework classes and works fine when get the data but doesn't work when post anything and i getting the next error message: "(400) Bad Request".

这是我的客户code:

This is my client code:

//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的配置文件标记:

This my <system.serviceModel> tag in wcf config file:

<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 在客户端应用程序:

And my app.config in client application:

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

在一个首先我虽然该问题存在于信访的重量,但我看到使用招的字节发送的请愿书仅115.903字节(〜0.11MB)。 任何想法?

In a first instance I though that the problem resides in the weight of the petition but i see using Fiddler that bytes send for the petition are only 115.903 bytes (~0.11MB). Any idea?

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

As you can see is a simple example but don't works :(

感谢您的帮助! :)

推荐答案

您必须设置 maxReceivedMessageSize readerQuotas (如果需要的话)上的服务从客户发布数据时。您的客户端的配置已经修改 maxReceivedMessageSize 这适用于从服务中获取数据,但是,当你发送大数据量的服务,您必须修改它的配置也是如此。

You must set maxReceivedMessageSize and readerQuotas (if needed) on the service when posting data from client. Your client configuration has modified maxReceivedMessageSize which works for getting data from service but when you send large amount of data to the service you must modify its configuration as well.

是这样的:

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

这篇关于WCF错误400错误的请求时,POST一些数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆