开发者

Trying to set up a controller action as Xml endpoint

I wanted to build a POX endpoint by using an ASP.NET MVC 2 controller action. I thought I would be able to reuse a lot of working code and be done in 15 min tops. I was wrong. My action looks like this:

[HttpPost]
[ValidateInput(false)]
public ContentResult DoSomething(string xml)

The ValidateInput attribute is required because you'll get a nasty validation exception otherwise when posting Xml to the action.

The client code:

var req = (HttpWebRequest)WebRequest.Create(endPoint);
req.Method = "POST";
req.ContentType = "text/xml";
req.Headers.Add("Accept-Encoding", "gzip,deflate,sdch");
// ...open request, read response now

This is working code. The following request is sent to the endpoint (fiddler2)

POST http://doerak/Veekijker/Service.aspx/Melding HTTP/1.1
Content-Type: text/xml
Accept-Encoding: gzip,deflate,sdch
Host: theHost
Content-Length: 2220
Expect: 100-continue
Connection: Keep-Alive

Xml=theXml

However, when I remove the "Accept-Encoding" header from the client code, the xml string parameter of my controller action is null.

The request without the accept-encoding header looks like this

POST http://doerak/Veekijker/Service.as开发者_C百科px/Melding HTTP/1.1
Content-Type: text/xml
Host: theHost
Content-Length: 2220
Expect: 100-continue

Xml=theXml

How can I use my controller action, without having to set the Accept-Encoding header on the client?


This for sure isn't text/xml that you're sending in the request body. It's a standard form name=value pair.

Either:

  • really send the data as XML blob (and that maybe needs an attribute at the method)
  • or use the standard Content-Type that all HTML forms use (which is application/x-www-form-urlencoded), and escape the value with URL encoding.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜