400 Bad Request:使用JScript / VBScript消耗WCF basicHttpBinding(Soap)

时间:2010-02-15 13:55:21

标签: soap wcf javascript basichttpbinding

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 Bad Request。我在stackoverflow中读取类似的线程..有人说它的肥皂消息格式化问题。

如果我从小提琴手那里拿到它,这就是这个消息。

2 个答案:

答案 0 :(得分:1)

尝试将您的操作从IHelloService更改为HelloService

让我问你,你为什么要这么做呢。只需添加webHttpBinding并使用JSON。

查看一个非常简单的示例 here

答案 1 :(得分: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