【发布时间】:2011-06-24 23:33:34
【问题描述】:
我有一个只允许 HTTP GET 请求的 WCF 服务:
[WebInvoke(Method="GET", ResponseFormat=WebMessageFormat.Json)]
public string GetAppData()
使用 webHttpBinding 公开服务
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="AppSvcBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
我的客户的配置看起来像
<system.serviceModel>
<client>
<endpoint address="http://localhost/AppService/Service.svc"
binding="webHttpBinding"
bindingConfiguration="webHttpBindingConfig"
contract="AppSvc.IService"
behaviorConfiguration="AppSvcBehavior"
name="AppSvcClient">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
</client>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingConfig">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="AppSvcBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
我的客户端代码很简单
ServiceClient client = new ServiceClient("AppSvcClient");
String result = client.GetAppData();
执行此代码时出现错误:
远程服务器返回意外响应:(405) Method Not Allowed。
我检查了提琴手,发现我的客户端正在发送一个 POST 消息,而服务需要一个 GET 因此错误。
我想知道如何配置客户端,以便向服务发送 GET 请求。
【问题讨论】:
-
服务器端配置的其余部分是什么样的?
标签: c# wcf wcf-binding wcf-client