WCF REST Starter Kit2 POST Method Not Allowed 405 Code

Last post 10-16-2009 1:08 PM by randallt. 5 replies.

Sort Posts:

  • WCF REST Starter Kit2 POST Method Not Allowed 405 Code

    10-14-2009, 2:00 AM
    • Member
      136 point Member
    • chintupawan
    • Member since 09-25-2007, 4:08 PM
    • Posts 50

    Hello every one.

    I have downloaded WCF REST Starter Kit2 and created a Rest Collection Service application using default template it is working well. I tried GET and POST Data this is ok. Now In Code behind page of Service .svc I removed those Default CollectionServiceBase<SampleItem> and ICollectionService<SampleItem> and added my own IPostalContract. Now I am not able to POST DATA it is saying Method Not Allowed but GET is working fine.

    [ServiceContract]
        public interface IPostContract
        {
            [OperationContract]
            [WebGet(UriTemplate = "post/{id}")]
            Post GetPost(string id);

            [OperationContract]
            [WebGet(UriTemplate = "posts")]
            PostCollections GetPosts();

            [OperationContract]
            [WebInvoke(Method = "Post", UriTemplate = "", BodyStyle = WebMessageBodyStyle.Wrapped , ResponseFormat=WebMessageFormat.Xml)]
            PostCollections AddPost(Post post);
        }

    and I implemented this in codebehind page of Service.svc like this

    Markup is this

    <%@ ServiceHost Language="C#" Debug="true" Service="Geeks_Lounge_Services.Service" Factory="Microsoft.ServiceModel.Web.WebServiceHost2Factory"%>

    [ServiceBehavior(IncludeExceptionDetailInFaults = true, InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single)]
        [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
       public class Service:IPostContract
        {
            // TODO: These variables are used by the sample implementation. Remove if needed
          

           
            public Post GetPost(string id)
            {
                // TODO: Change the sample implementation here
                PostDS ds = new PostDS();
                Post p = ds.GetSingle(Convert.ToInt32(id));
                return p;
            }

          
            public PostCollections GetPosts()
            {
                // TODO: Change the sample implementation here
                PostDS ds = new PostDS();
                PostCollections p = ds.GetAll();
                return p;
            }

            public PostCollections AddPost(Post p)
            {
                PostDS ds = new PostDS();
                return ds.AddPost(p);
            }
       }

    Web Config is as it is

    <?xml version="1.0"?>
    <configuration>
        <system.web>
            <compilation debug="true"/>
            </system.web>
        <system.serviceModel>
            <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
        </system.serviceModel>
    </configuration>


    Please help me where I am making mistake or suggest me if there are any setting I am missing any where



    ASP.NET C# new bee...
  • Re: WCF REST Starter Kit2 POST Method Not Allowed 405 Code

    10-14-2009, 12:03 PM
    • Member
      90 point Member
    • randallt
    • Member since 02-11-2009, 11:53 AM
    • Posts 30

    What are the URIs that you are using to hit the service (the GET and the POST operations)? 

  • Re: WCF REST Starter Kit2 POST Method Not Allowed 405 Code

    10-15-2009, 12:10 AM
    • Member
      136 point Member
    • chintupawan
    • Member since 09-25-2007, 4:08 PM
    • Posts 50

    http://localhost:49065/Service.svc/post/4 is working fine get method (tried in fiddler)

    http://localhost:49065/Service.svc/post for list is working fine (tried in fiddler)

    http://localhost:49065/Service.svc for add method this one saying Method not allowed (tried in fiddler)



    ASP.NET C# new bee...
  • Re: WCF REST Starter Kit2 POST Method Not Allowed 405 Code

    10-15-2009, 1:21 PM
    • Member
      90 point Member
    • randallt
    • Member since 02-11-2009, 11:53 AM
    • Posts 30

    Hi.  Method names are case sensitive (per the HTTP 1.1 spec).  In your contract for the AddPost operation you have specified the method in the [WebInvoke] as "Post".  This should be "POST", as this is what fiddler will send.

    Try making that change and see if it works.

    Thanks 

  • Re: WCF REST Starter Kit2 POST Method Not Allowed 405 Code

    10-16-2009, 9:08 AM
    • Member
      136 point Member
    • chintupawan
    • Member since 09-25-2007, 4:08 PM
    • Posts 50

    yeaah u are right that was the one giving me the problem..

    cheers mate

    ASP.NET C# new bee...
  • Re: WCF REST Starter Kit2 POST Method Not Allowed 405 Code

    10-16-2009, 1:08 PM
    • Member
      90 point Member
    • randallt
    • Member since 02-11-2009, 11:53 AM
    • Posts 30

    Please mark the response that provided the correct answer for future users!

    Thanks 

Page 1 of 1 (6 items)