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
[OperationContract]
[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
http://localhost:51561/AceWebService.svc/GetUsers
here is the webconfig part:
<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 referenced all the questions available here on stackoverflow .. not getting any help .. please suggest changes.
Thnx
+3
source to share
2 answers
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)]
[ServiceContract]
public class HelloService
{
[WebGet(UriTemplate = "helloworld")]
[OperationContract]
public string HelloWorld()
{
return "Hello World!";
}
}
0
source to share