I have a WCF service that only allows HTTP GET requests:
[WebInvoke(Method="GET", ResponseFormat=WebMessageFormat.Json)] public string GetAppData()
Service is opened using webHttpBinding
<system.serviceModel> <bindings> <webHttpBinding> <binding name="AppSvcBinding"> <security mode="TransportCredentialOnly"> <transport clientCredentialType="Windows" /> </security> </binding> </webHttpBinding> </bindings> <behaviors>
I have my client whose configuration looks like
<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>
My client code is simple
ServiceClient client = new ServiceClient("AppSvcClient"); String result = client.GetAppData();
When executing this code, I get an error message:
The remote server returned an unexpected response: (405) Method not allowed.
I checked with a violinist and found that my client was sending a POST message, while the service was expecting a GET, hence an error.
I want to know how to configure the client to send a request to the GET service.
source share