大家好,祝大家好,在WCF处理来自XML HTTP的POST请求
根据上述标题,我试图处理来自WCF中XML HTTP的POST请求。实际上,我已经可以使用HTTP Web Request处理请求,但由于旧库以这种形式发送请求(如代码中所示,我们使用的是MSXML2名称空间),因此我们必须在此处维护此要求。
这里是前端代码(旧库,将请求发送)
MSXML2.ServerXMLHTTP xmlhttp = new MSXML2.ServerXMLHTTP();
xmlhttp.open("POST", "http://localhost/RestService/RestServiceImpl.svc/auth", false);
xmlhttp.setRequestHeader("User-Agent", "Jakarta Commons-HttpClient/2.0.2");
String ClientRequest = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone= ""yes""?> <RequestData xmlns=""http://www.eysnap.com/mPlayer""> <details>Ashu|29|7 Years|.NET</details></RequestData>";
xmlhttp.send(ClientRequest);
int readyState = xmlhttp.readyState;
int status = xmlhttp.status;
虽然这里的代码为WCF,我没能处理:
public ResponseData Auth(RequestData rData)
{
try
{
Logger.log.Info("attempting to send request");
// Call BLL here
var data = rData.details.Split('|');
var response = new ResponseData
{
Name = data[0],
Age = data[1],
Exp = data[2],
Technology = data[3]
};
Logger.log.Info("Sending request...");
return response;
}
catch(System.Exception ex)
{
Logger.log.Fatal(ex.Message);
return null;
}
}
在web.config中,我已经将绑定更改为“customBinding”而不是“webHttpBinding”,因为我在获取请求时使用RAW格式而不是JSON格式的错误。
通过论坛和其他网站搜索后,我试着相应地改变web.config,但得到了xmlhttp status 400(Bad Request)。
在此先感谢您的建议。
您是否试图使用Fiddler监视您的请求?此外,RAW消息是由于您的请求未设置Content-Type标题属性。只需将其设置为application/xml或application/json,即可得到解决 – Rajesh 2012-03-27 11:28:58