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.

4

1 回答 1

2

以下应该有效:

<httpHandlers>   
    <add verb="*" path="EndPoint" type="MyHandler/*" />
</httpHandlers>
于 2013-02-08T06:44:48.183 回答