开发者

400 Bad Request : Consuming WCF basicHttpBinding (Soap) using JScript/VBScript

开发者 https://www.devze.com 2022-12-20 09:32 出处:网络
var oXMLDoc, oXMLHttp, soapRequest, soapResponse; oXMLHttp = new ActiveXObject(\"Microsoft.XMLHTTP\");
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><开发者_JAVA技巧;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);

Whats wrong with this JScript? why am I getting 400 Bad Request. I read similar threads in stackoverflow .. some say its soap message formatting problem.

This is what the message looks like if I take it from fiddler.


Try changing your action from IHelloService to HelloService.

And let me ask you, why are you doing it the hard way. Just add a webHttpBinding and use JSON.

See a very easy example here.


I had to change your code to the following to get it to run in VBSEdit...then I (obviously) got the error about it not being able to find the resource...but change your code to this and see if it makes a difference?

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
0

精彩评论

暂无评论...
验证码 换一张
取 消