0
var oXMLDoc, oXMLHttp, soapRequest, soapResponse;

oXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");

oXMLHttp.open("POST", "http://nerdbox/HelloService.svc", false);

// Add HTTP headers
oXMLHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
oXMLHttp.setRequestHeader("SOAPAction", "http://tempuri.org/IHelloService/SayHello");

// Form the message
soapRequest = '<?xml version="1.0" encoding="utf-16"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><SayHello xmlns="http://tempuri.org/"><name>Zuhaib</name></SayHello></soap:Body></soap:Envelope>';

WScript.Echo("Request : " + soapRequest);

oXMLHttp.send(soapRequest);
soapResponse = oXMLHttp.responseXML.xml;
WScript.Echo("Respose : " + soapResponse);

这个 JScript 有什么问题?为什么我收到 400 错误请求。我在stackoverflow中读到了类似的线程。有人说它的soap消息格式问题。

如果我从提琴手那里得到消息,这就是它的样子。

4

2 回答 2

1

尝试将您的操作从 更改IHelloServiceHelloService

让我问你,你为什么要这么辛苦。只需添加一个 webHttpBinding 并使用 JSON。

在此处查看一个非常简单的示例。

于 2010-02-15T14:20:05.070 回答
0

我必须将您的代码更改为以下代码以使其在 VBSEdit 中运行...然后我(显然)收到有关它无法找到资源的错误...但是将您的代码更改为此并查看它是否使有区别吗?

Dim oXMLDoc, oXMLHttp, soapRequest, soapResponse

Set oXMLHttp = CreateObject("Microsoft.XMLHTTP")

oXMLHttp.open "POST", "http://nerdbox/HelloService.svc", False

'// Add HTTP headers
oXMLHttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
oXMLHttp.setRequestHeader "SOAPAction", "http://tempuri.org/IHelloService/SayHello"

'// Form the message
soapRequest = "<?xml version=""1.0"" encoding=""utf-16""?><soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""><soap:Body><SayHello xmlns=""http://tempuri.org/""><name>Zuhaib</name></SayHello></soap:Body></soap:Envelope>"

WScript.Echo "Request : " + soapRequest

oXMLHttp.send soapRequest
soapResponse = oXMLHttp.responseXML.xml
WScript.Echo "Respose : " + soapResponse
于 2010-07-30T03:24:12.953 回答