我有一个WCF服务,它只允许HTTP GET请求:
[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();
The Remote Server returned an unexpected response: (405) Method Not Allowed.
我检查了fiddler并发现我的客户端正在发送POST消息,而服务期望GET因此出错.
我想知道如何配置客户端,以便向服务发送GET请求.
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。