Search code examples
wcfhttp-status-code-400

WCF Method giving 400 Bad Request in GET/POST method


I have newly created a WCF and m facing 400 bad req error when i try to hit the url from the browser.

my service contract looks like

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

I have already made the entry in webconfig as

<serviceMetadata httpGetEnabled="true"/>

url that i hit in the browser is

http://localhost:51561/AceWebService.svc/GetUsers

here is the part of webconfig:

<system.serviceModel>
    <services>
        <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 
          automatically.
      -->
                <identity>
                    <dns value="localhost"/>
                </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <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"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>
</system.serviceModel>

Have refered to all the ques available here in stackoverflow.. not getting any help.. please suggest the changes.

thnx


Solution

  • You have used a wsHttpBinding defined on your endpoint. Just change it to webHttpBinding and that should get it working.