4

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

1Mayur
  • 3,419
  • 5
  • 40
  • 64

2 Answers2

3

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

Rajesh
  • 7,766
  • 5
  • 22
  • 35
0

Firstly, use WebGet for GET requests. Secondly, get the service working without a service contract interface, then when its working, move the contract into an interface.

this works for me:

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

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

}
reach4thelasers
  • 26,181
  • 22
  • 92
  • 123