Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi experts,

I am learning WCF basics now, and i tried a sample REST WCF application. When i run and tried to invoke the method it shows method not allowed.
When i ran my service, it ran with the url

http://localhost:13493/WCFRestService.svc[^]

and when i invoke the method by editing the url
http://localhost:13493/WCFRestService.svc/JSONData/mani[^]
it displays as Method not allowed.

the code i am using is
Interface
C#
[ServiceContract]
   public interface IWCFRestService
   {
       [OperationContract]
       [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped,
        UriTemplate = "/JSONData/{id}")]
       string JSONData(string id);
   }


Class that inherited the interface

C#
public class WCFRestService : IWCFRestService
   {
       public string JSONData(string id)
       {
           return "requested number  " + id;
       }
   }


and web.config file has
XML
<system.serviceModel>
        <services>
            <service behaviorConfiguration="WCFRestService.WCFRestServiceBehavior" name="WCFRestService.WCFRestService">
                <endpoint address="" binding="webHttpBinding" behaviorConfiguration="webHttp" contract="WCFRestService.IWCFRestService">
                    <identity>
                        <dns value="192.168.100.75"/>
                    </identity>
                </endpoint>
                <endpoint name="mexHttpBinding" address="mex"  binding="mexHttpBinding" contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://192.168.100.75/WCFService"/>
          </baseAddresses>

        </host>
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="WCFRestService.WCFRestServiceBehavior">
                    <serviceMetadata httpGetEnabled="true"/>
                    <serviceDebug includeExceptionDetailInFaults="false"/>
                </behavior>
            </serviceBehaviors>
            <endpointBehaviors>
                <behavior name="webHttp">
                    <webHttp/>
                </behavior>
            </endpointBehaviors>
        </behaviors>
    </system.serviceModel>
Posted
Comments
Ron Beyer 22-Jul-13 11:47am    
I believe, and I'm not posting this as a solution because I'm not sure, but you are setting the WebInvoke method to "POST", if you are typing in a web browser I believe it is using "GET" not "POST" to get the page. Try changing that to "GET" instead of post...
Manikandan Sekar 22-Jul-13 11:53am    
Thanks Ron Beyer for your your valuable timing and Response and believe me its worked. I just forgot to check the webinvoke. Thanks once again

1 solution

I solved my problem with the help from Ron Beyer

C#
public interface IWCFRestService
   {
       [OperationContract]
       [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped,
        UriTemplate = "/JSONData/{id}")]
       string JSONData(string id);
   }

It must be GET instead of POST.
SO its working fine and service has invoked.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900