0

I have check ALL related topics, but nothing was helpful. I do not use url rewriting, I do not click any buttons. My web service expects POST from other service and then it should returns 200 OK with certain payload.

Some of you might say "Ok, the specific servlet does not support post". The most confusing thing is that when I send POST from Chrome Simple REST client it works! When third party web service sends me the same POST it gives me an error.

Here's what I do, I use ASP.NET development server as web service available to be reached from outside by tunneling (thanks to this topic) -> this works from REST client. And then wait for POST which gives me "The HTTP verb POST used to access path 'EndPoint' is not allowed"

Here's web.config

<httpHandlers>   
      <add verb="*" path="EndPoint"
          type="MyHandler" />     
</httpHandlers> 

My code that parses POST message and returns the required message:

public class MyHandler : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        var stream = context.Request.InputStream;
        byte[] buffer = new byte[stream.Length];
        stream.Read(buffer, 0, buffer.Length);
        string xml = Encoding.UTF8.GetString(buffer);

        StringBuilder sb = new StringBuilder();
        XDocument doc = XDocument.Parse(xml);            

        var id = XElement.Parse(xml)
            .Descendants("id")
            .First()
            .Value;

        string file = "c:/message.xml";            
        XDocument d = XDocument.Load(file);

        d.Descendants("context").Where(x => x.Attribute("id").Value == id).Single().SetAttributeValue("value", "54");
        d.Save(file);  

        string responseMessage = @"
            <?xml version=""1.0"" encoding=""UTF-8""?>            
            <Message>                
                <code>Fine</code> 
            </Message>
            ";

        context.Response.StatusCode = 200;     
        context.Response.AddHeader("Content-Type", "application/xml");
        context.Response.Write(responseMessage);            

    }

This is log from Tunnel monitor

<!-- 
[HttpException]: The HTTP verb POST used to access path &#39;/EndPoint/&#39; is not allowed.
   at System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state)  at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
-->

EDIT Answer was straightforward. External service was sending to EndPoint/ instead of subscribed url without "/" i.e. EndPoint.

Community
  • 1
  • 1
supermus
  • 576
  • 1
  • 9
  • 21
  • The client seems to be POSTing to `/EndPoint/` Have you tried POSTing to `/EndPoint` without the trailing slash? – Darin Dimitrov Feb 07 '13 at 22:20
  • Hi Darin, actually now client is POSTing to /EndPoint without slash. Wait, maybe you are right. The "client" here is actually subscription service. Maybe itself adds slash at the end. I will check this with programmer of external client. Thanks – supermus Feb 07 '13 at 22:22
  • There seems to be some module in your application which is redirecting or overwriting the request to `/EndPoint/`. Have you verified the traffic between the client and the server with Fiddler? – Darin Dimitrov Feb 07 '13 at 22:25
  • Will it be ok if I put / in path like this: path="EndPoint/" ? The problem is that service blacklist me when my service do not response, and it extends message sending time, so I need to do many things all over again, and wait, etc – supermus Feb 07 '13 at 22:34
  • 1
    I am not sure if this will work but you could try it. You might also try `path="EndPoint/*"`. – Darin Dimitrov Feb 07 '13 at 22:34
  • This was the answer. Thank you, I was breaking my leg over this. @#@! – supermus Feb 08 '13 at 01:13
  • I have posted that as answer. – Darin Dimitrov Feb 08 '13 at 06:45

1 Answers1

2

The following should work:

<httpHandlers>   
    <add verb="*" path="EndPoint" type="MyHandler/*" />
</httpHandlers>
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928