I have a WCF REST service. I verified Webconfig file and all config items are fine.
I am getting EndPoint not found error with below code. I will add parameters to GetDateTime method.
[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
string GetDateTime();
NO Endpoint error with below code.
[OperationContract]
[WebGet(UriTemplate = "/")]
string GetDateTime();
I want to get this running with WebInvoke. Any help is appreciated!
Here is the config details from Web.config file.
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="SampleRest.Service1" behaviorConfiguration ="ServiceBehaviour">
<endpoint address="" binding ="webHttpBinding" contract="SampleRest.IService1" behaviorConfiguration ="web" >
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<!-- 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="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
Here is the URL that I tried.
I have the following code:
[WebInvoke(ResponseFormat=WebMessageFormat.Json, RequestFormat= WebMessageFormat.Json)]
string PostDateTimeAndReturnAsString(DateTime dateTime);
The implementation of the above method as shown below:
public string PostDateTimeAndReturnAsString(DateTime dateTime)
{
return dateTime.ToString();
}
My web.config as shown below:
<services>
<service name="XMLService.Service1" behaviorConfiguration="default">
<endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" bindingConfiguration="RestBinding" name="Service1" contract="XMLService.IService1" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
My raw request from fiddler as below:
POST http://localhost/XMLService/Service1.svc/postdatetimeandreturnasstring HTTP/1.1
User-Agent: Fiddler
Content-Type: application/json
Host: localhost
Content-Length: 30
"\/Date(1330081170513+0000)\/"
I get back the a HTTP 200 OK code with the following response back:
"24\/02\/2012 11:07:59"
NOTE: when date time is a parameter that needs to be passed in json format that is the way you need to pass it as shown in the raw request format ( the value that i used was during my execution the current date time, using the same value should return the value as shown below)