我试图调用一个Web服务从数据库中检索一些XML数据。如果我使用静态文件,那么Ajax调用可以正常工作,例如:
$.ajax({
type: "GET",
url: "test2.xml",
data: buildXMLDataRequestObject(),
dataType: "xml",
success: getXMLDataSucceeded,
error: getXMLDataFailed
});
但当我尝试调用Web服务时失败,例如:
$.ajax({
type: "POST",
url: "Services/CheckOutService.svc/GetXMLData",
data: buildXMLDataRequestObject(),
dataType: "xml",
success: getXMLDataSucceeded,
error: getXMLDataFailed
});
“传入消息具有
意外的消息格式“Raw”。这个
的预期消息格式
因为WebContentTypeMapper
未在绑定上配置。
WebContentTypeMapper了解更多
详细信息。”
GetXMLData方法如下所示:
[OperationContract]
[WebInvoke(ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
string GetXMLData(XMLDataRequest request);
...
public string GetXMLData(XMLDataRequest request)
{
request.ShopperId = ShopperId;
return checkOutManager.GetXMLData(request);
}
非常
第1行,位置1。
我尝试过contentType:“text/xml”和contentType:“application/xml”,两者都给出了相同的错误。
编辑:昨天(8月30日)我注意到,如果省略ajax调用的data参数,服务调用就会成功。我想JSON对象有点问题。目前,我已经在应用程序的服务器端实现了这个功能,但我确实打算在有时间的时候再讨论一下。