Rest service returns “method not allowed” on webpage

51 views Asked by At

I'm trying to pass object parameter as JSON format to WCF restful service.

service contract code like this;

 [OperationContract]
 [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "xml/{id}")]
 string XMLData(string ID);

And my web.config file like this;

<system.serviceModel>
<services>
  <service name="RestService.RestServiceImpl" behaviorConfiguration="ServiceBehaviour">
    <endpoint address="" binding="webHttpBinding" contract="RestService.IRestServiceImpl" behaviorConfiguration="web">
    </endpoint>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehaviour">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="web">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
</behaviors>
<protocolMapping>
  <add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

When I trying call the service with "http://localhost/serviceurl/xml/123" url, Service returned "Method not allowed" error message.

1

There are 1 answers

0
Harshit Verma On

I resolved it. I had to remove the <ProtocolMapping> and <ServiceHostingEnvironment> tag from the web.config file.

Its works fine now.