I'm writing a simple web service DEMO using .net framework, and I'm testing the web service with a tool named "soapUI". I'm trying to send the request message by HTTP HOST with XML data but I have an issue.
[WebMethod]
[WebInvoke(ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
public XmlDocument loginrequest(string XmlString)
{
XmlDocument Xdoc = new XmlDocument();
// parse request XML data, and return response XML document
// ......
return Xdoc;
}
<configuration>
<system.web>
<compilation targetFramework="4.5" debug="true"/>
<httpRuntime targetFramework="4.5" requestValidationMode="2.0"/>
<pages validateRequest="false"/>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>
</configuration>
application/x-www-form-urlencoded)
:XmlString=%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%3E%3CLoginRequest%3E%3CUser%3E%3CUserName%3ETestUser%3C%2FUserName%3E%3CPassword%3E123456%3C%2FPassword%3E%3C%2FUser%3E%3CSeqNum%3E%3C%2FSeqNum%3E%3C%2FLoginRequest%3E
text/xml
or application/xml
):<?xml version="1.0" encoding="utf-8"?>
<LoginRequest>
<User>
<UserName>TestUser</UserName>
<Password>123456</Password>
</User>
<SeqNum>
</SeqNum>
</LoginRequest>
Here is the full error message:
System.InvalidOperationException: Request format is invalid: application/xml.
at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
Summary: since the soapUI seems like to be a widely used test tool, it should be fine. What I want to know is that, do I need to change anything in my web service code or Web.config
to support XML formatted HTTP POST data?
Actually what I was trying to do, is send a XML string as the entity-body of a HTTP POST request, instead of a query string. I'm still not sure why I got
Invalid request format
But finally I've solved the issue by reading the request entity-body through HttpContext.Current.Request.InputStream
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.