WCF method giving 400 Bad Request in GET / POST method

I recently created WCF and m faced 400 req errors when I try to hit a URL from the browser.

my service contract looks like

[WebInvoke(Method = "GET", UriTemplate = "GetUsers")]
string GetUsers();


I have already made an entry in webconfig as

<serviceMetadata httpGetEnabled="true"/>


the url I click in the browser is



here is the webconfig part:

        <service name="AceWebService.AceWebService" behaviorConfiguration="AceWebService.AceWebServiceBehavior">
            <!-- Service Endpoints -->
            <endpoint address="" binding="wsHttpBinding" contract="AceWebService.IAceWebService">
          Upon deployment, the following identity element should be removed or replaced to reflect the 
          identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
                    <dns value="localhost"/>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
            <behavior name="AceWebService.AceWebServiceBehavior">
                <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                <serviceMetadata httpGetEnabled="true"/>
                <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                <serviceDebug includeExceptionDetailInFaults="true"/>


Have referenced all the questions available here on stackoverflow .. not getting any help .. please suggest changes.



source to share

2 answers

You used the wsHttpBinding defined on the endpoint. Just change it to webHttpBinding and that should make it work.



First, use WebGet for GET requests. Second, get the service running without the service contract interface, and then when it is running, translate the contract into the interface.

this works for me:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class HelloService 

    [WebGet(UriTemplate = "helloworld")]
    public string HelloWorld()
         return "Hello World!";





All Articles