【发布时间】:2018-11-06 00:52:17
【问题描述】:
我正在尝试通过简单页面上的 JS 调用提交 SOAP 发布请求。提交时,如果我通过浏览器调试,我会得到:
POST http://localhost:63748/DistGamingWebService.svc 400(错误请求)
我有一个 Web 服务(如上),它连接到一个非常基本的“数据库”类型的服务器,两者都在本地运行。两者之间的连接工作正常 - 当我运行 WCF 测试客户端时,我可以调用方法并按预期获取返回值。
我已经根据测试 WCF 客户端的 XML 请求设置了 SOAP 消息,但我仍然收到 400 错误请求。 req.status 的值始终为 1。
我在下面包含了我的 JS 调用和 POST 消息格式。
function GetNumBossesTest() {
req = null;
if (window.XMLHttpRequest != undefined)
req = new XMLHttpRequest();
else {
req = new ActiveXObject("Micosoft.XMLHTTP");
}
req.open("POST", "http://localhost:63748/DistGamingWebService.svc", true);
req.setRequestHeader("Content-Type", "text/xml");
req.setRequestHeader("SOAPAction", "http://tempuri.org/IDistGamingWebService/GetNumBosses");
var sMsg = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><Action soap:>http://tempuri.org/IDistGamingWebService/GetNumBosses</Action></soap:Header><soap:Body><GetNumBosses xmlns="http://tempuri.org/" /></soap:Body></s:Envelope>';
req.send(sMsg);
if (req.status == 200)
alert(req.responseText);
}
在上面的示例中,我通过将消息完全放在一行中来简化消息。当我通过 Fiddler 和 Chrome 调试检查请求时,消息的格式与 JS 插入它的方式完全相同。
就我的 web svc 上的界面而言,我有以下几点:
[ServiceContract]
public interface IDistGamingWebService
{
[OperationContract]
int GetNumBosses();
}
这个接口的实现只是远程调用另一个类似数据库的服务器。
提前谢谢你。
【问题讨论】:
标签: javascript c# wcf soap