【发布时间】:2011-03-08 17:35:22
【问题描述】:
我的本地计算机上有一个 WCF 服务,它的工作方式类似于客户端应用程序和远程数据库之间的“桥梁”。
WCF 服务与实体框架类一起工作,在获取数据时工作正常,但在发布任何内容时不起作用,我收到下一条错误消息:“(400) 错误请求”。
这是我的客户端代码:
//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);
这是我在 wcf 配置文件中的 <system.serviceModel> 标签:
<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)。 任何想法?
如您所见,这是一个简单的示例,但不起作用:(
感谢您的帮助! :)
【问题讨论】:
-
把你的服务接口放在这里