Get simple response from SOAP service with classic asp - soap

I have been tasked with obtaining a response from a SOAP request, using classic asp. The request is about as basic as it gets - I just need to fire off 3 parameters to a web service URL and write out the response (which is in simple plain text format). I've checked the service using a couple of SOAP testing utilities and it outputs the response fine.
I've also read about 10 different tutorials on consuming SOAP feeds in classic ASP, but none of them seem to work at all.
The latest one I'm trying has given me the following code:
<%
Set oXmlHTTP = CreateObject("Microsoft.XMLHTTP")
oXmlHTTP.Open "POST", "http://www.webservicehost.co.uk/B2bservice.asmx?wsdl", False
oXmlHTTP.setRequestHeader "Content-Type", "application/soap+xml; charset=utf-8"
oXmlHTTP.setRequestHeader "SOAPAction", "http://ourNameSpace/ourFunction"
SOAPRequest = _
"<?xml version=""1.0"" encoding=""utf-8""?>" &_
"<soap12:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap12=""http://www.w3.org/2003/05/soap-envelope"">" &_
"<soap12:Body>" &_
"<ourFunction xmlns=""http://ourNameSpace/"">" &_
"<Ccode>OurCode</Ccode>" &_
"<Pword>1d2s45a</Pword>" &_
"<OrderNo>9876</OrderNo>" &_
"</ourFunction>" &_
"</soap12:Body>" &_
"</soap12:Envelope>"
oXmlHTTP.send SOAPRequest
response.write oXmlHTTP.responseText
%>
I have all the correct values for the POST URL, the Ccode, Pword and OrderNo variables, but have no idea what to use for the "SoapAction" or values. As a result, when I run the page I just get an error:
soap:SenderUnable to handle request without a valid action parameter. Please supply a valid soap action.
Can anyone suggest what to use for the SoapAction and ourFunction xmlns values?
Many thanks for any pointers...

your code should work ok with a few changes
<%
Response.Write "<br>START<hr>"
Set oXmlHTTP = CreateObject("Microsoft.XMLHTTP")
oXmlHTTP.Open "POST", "http://www.crusaderb2b.co.uk/b2bservice.asmx", False
oXmlHTTP.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
oXmlHTTP.setRequestHeader "SOAPAction", "http://crusaderb2b.co.uk/TrackingId"
SOAPRequest = _
"<?xml version=""1.0"" encoding=""utf-8""?>" &_
"<soap12:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap12=""http://www.w3.org/2003/05/soap-envelope"">" &_
"<soap12:Body>" &_
"<ourFunction xmlns=""http://ourNameSpace/"">" &_
"<Ccode>OurCode</Ccode>" &_
"<Pword>1d2s45a</Pword>" &_
"<OrderNo>9876</OrderNo>" &_
"</ourFunction>" &_
"</soap12:Body>" &_
"</soap12:Envelope>"
oXmlHTTP.send SOAPRequest
Response.Write oXmlHTTP.responseText
Response.Write "<br>END<hr>"
%>
changes are
remove ?wdsl
change content type
method call needs to be the same server of the webservice as it's the method name
added
I changed the code as you provided the Web Service. All you need you have in the service page as:
original image here
answer with the code above:

Related

Classic asp - only receiving part of soap response

I am trying to call a soap request from classic asp (it will be updated at some later point, but for now it stays classic asp), but I'm only getting half of the response?
When I use the request string in SoapUI, I get the response I'm looking for, but in asp I only receive part of the response??
ASP Request:
Set oXmlHTTP = CreateObject("Microsoft.XMLHTTP")
oXmlHTTP.Open "POST", "http://webservice-string?wsdl", False
oXmlHTTP.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
oXmlHTTP.setRequestHeader "SOAPAction", "urn:action"
SOAPRequest = _
"<?xml version=""1.0"" encoding=""utf-8""?>" &_
"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:head=""http://header.com"" xmlns:ser=""http://service.com"" xmlns:add=""http://service.com/domain/address"">" &_
"<soapenv:Header>" &_
"<head:OnBehalfOfUserId>stine</head:OnBehalfOfUserId>" &_
"<head:RequestId>?</head:RequestId>" &_
"<head:AuthenticationHeader>" &_
"<head:SessionID>?</head:SessionID>" &_
"</head:AuthenticationHeader>" &_
"</soapenv:Header>" &_
"<soapenv:Body>" &_
"<ser:searchVisitationRequest>" &_
"<ser:UserId>Stine</ser:UserId>" &_
"<ser:RequestId>?</ser:RequestId>" &_
"<add:SomeId>1234</add:SomeId>" &_
"</ser:searchVisitationRequest>" &_
"</soapenv:Body>" &_
"</soapenv:Envelope>"
On Error Resume Next
oXmlHTTP.send SOAPRequest
If Err.Number Then
Err.Clear
Else
SOAPResponse = oXmlHTTP.responseXML.text
End If
On Error Goto 0
if len(SOAPResponse) > 0 then
Response.Write SOAPResponse
end if
ASP Response:
2018-06-25T09:56:36.016+02:00server_ID{bla bla}5
SoapUI response
(made from same request - contains "SearchVisitation" which is the result I need!)
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<searchVisitationResponse xmlns="http://service.com">
<ReplyInfo>
<ReplyTimestamp>2018-06-25T08:47:48.204+02:00</ReplyTimestamp>
<ServerId>server_ID</ServerId>
<StatusMessage>{bla bla}</StatusMessage>
<TransactionDuration>3</TransactionDuration>
</ReplyInfo>
<SearchVisitation>
<OtherID>12345678</OtherID>
<SearchVisitationID>
<SubscriptionNo>Test1</SubscriptionNo>
</SearchVisitationID>
</SearchVisitation>
</searchVisitationResponse>
</S:Body>
</S:Envelope>
What am I doing wrong?
Turns out that
oXmlHTTP.setRequestHeader "SOAPAction", "urn:action"
was the part that would cause the request to error (I've - again - triple checked that the urn:action was correct).
Removing it gave me the correct response.

Check VAT Number at VIES with classic ASP + SOAP

I'm trying to check European VAT Number at VIES via Webservice:
with my poor knowledge I built the following routine:
<%
strEnvelope="<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:urn=""urn:ec.europa.eu:taxud:vies:services:checkVat:types"">"
strEnvelope=strEnvelope&"<soapenv:Header/>"
strEnvelope=strEnvelope&"<soapenv:Body>"
strEnvelope=strEnvelope&"<urn:checkVat>"
strEnvelope=strEnvelope&"<urn:countryCode>DE</urn:countryCode>"
strEnvelope=strEnvelope&"<urn:vatNumber>247856515</urn:vatNumber>"
strEnvelope=strEnvelope&"</urn:checkVat>"
strEnvelope=strEnvelope&"</soapenv:Body>"
strEnvelope=strEnvelope&"</soapenv:Envelope>"
set objHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
objHTTP.open "post", "http://ec.europa.eu/taxation_customs/vies/services/checkVatService"
objHTTP.setRequestHeader "Content-Type", "text/xml"
objHTTP.setRequestHeader "SOAPMethodName", "checkVat"
objHTTP.send strEnvelope
strReturn = objHTTP.responseBody
response.write strReturn
%>
but I got this answer
猼慯㩰湅敶潬数ç æ±­ç®çŒºæ…¯ãµ°æ ¢ç‘´ã©°â¼¯æ³æ•¨æ…­â¹³æµ¸ç¬æ…¯â¹°ç‰¯â½§æ½³ç¡æ”¯ç™®æ±¥ç¯â½¥ã¸¢çŒ¼æ…¯ã©°æ½‚祤㰾档æ¥å™«ç‘¡æ•’ç³æ¹¯æ•³ç æ±­ç®âˆ½ç‰µã©®æ¥æ”®ç‰µç¯â¹¡ç•¥çºç¡¡æ‘µç˜ºæ•©ã©³æ•³ç™²æ©ç¥æŒºæ•¨æ­£æ…–㩴祴数≳㰾潣湵牴ä¹æ‘¯ã¹¥ä•„⼼潣湵牴ä¹æ‘¯ã¹¥ç˜¼ç‘¡ç•Žæ‰­ç‰¥ãˆ¾ãœ´ã”¸ã”¶ã”±â¼¼æ…¶ä¹´æµµæ•¢ã¹²çˆ¼ç…¥æ•µç‘³æ…„整㈾㄰ⴷ㜰ㄭ⬵㈰〺㰰爯煥敵瑳慄整㰾慶楬㹤牴敵⼼慶楬㹤渼浡㹥ⴭ㰭港浡㹥愼摤敲ç³â´¾â´­â¼¼æ‘¡ç‰¤ç¥ã¹³â¼¼æ¡£æ¥å™«ç‘¡æ•’ç³æ¹¯æ•³ã°¾çŒ¯æ…¯ã©°æ½‚祤㰾猯慯㩰湅敶潬数> 猼慯㩰湅敶潬数ç æ±­çÂ®çŒºæ…¯ãµ°æ ¢ç‘´ã©°â¼¯æ³敨慭⹳浸ç¬慯⹰牯⽧潳ç¡æâ€Â¯Ã§â„¢Â®Ã¦Â±Â¥Ã§Â¯â½¥ã¸¢çŒ¼æ…¯ã©°æ½‚祤㰾档æ¥噫瑡敒ç³湯敳ç æ±­ç®∽牵㩮æÂ¥æâ€Â®Ã§â€°ÂµÃ§Â¯â¹¡ç•¥çº硡摵瘺敩㩳敳癲æ©ç¥挺敨正慖㩴祴数≳㰾潣湵牴ä¹摯㹥䕄⼼潣湵牴ä¹摯㹥瘼瑡畎扭牥㈾㜴ãâ€Â¸Ã£â€Â¶Ã£â€Â±Ã¢Â¼Â¼Ã¦â€¦Â¶Ã¤Â¹Â´Ã¦ÂµÂµÃ¦â€¢Â¢Ã£Â¹Â²Ã§Ë†Â¼Ã§â€¦Â¥Ã¦â€¢ÂµÃ§â€˜Â³Ã¦â€¦â€žÃ¦â€¢Â´Ã£Ë†Â¾Ã£â€žÂ°Ã¢Â´Â·Ã£Å“°ã„­â¬µãˆ°ã€ºã°°çˆ¯ç…¥æ•µç‘³æ…„整㰾慶楬㹤牴敵⼼慶楬㹤渼浡㹥ⴭ㰭港浡㹥愼摤敲ç³ⴾⴭ⼼摡牤ç¥㹳⼼档æ¥噫瑡敒ç³湯敳㰾猯慯㩰潂祤㰾猯慯㩰湅敶潬数>
can give some hints?
Thanks
The text representation of the response is in the responseText property, so:
strReturn = objHTTP.responseText

SOAP Request in Classic ASP

I have the following simple Soap request code. (using classic ASP)
I've read many tutorials on consuming SOAP feeds in classic ASP, but none of them seem to work at all.
I try the following code:
soapEnvelope = _
"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/""" &_
"xmlns:etp=""https://test.mpay24.com/soap/etp/1.5/ETP.wsdl"">" &_
"<soapenv:Header/>" &_
" <soapenv:Body>" &_
" <etp:SelectPayment>" &_
" <merchantID>XXXXXX</merchantID>" &_
" <mdxi>" &_
" <Order>" &_
" <Tid>cust9126</Tid>>" &_
" <Price>10.00</Price>" &_
" </Order>" &_
" </mdxi>" &_
" </etp:SelectPayment>" &_
" </soapenv:Body>" &_
" </soapenv:Envelope>"
Set SoapRequest = CreateObject("Microsoft.XMLHTTP")
Set myXML =Server.CreateObject("MSXML.DOMDocument")
myXML.Async=False
SoapRequest.Open "POST", "https://test.mpay24.com/app/bin/etpproxy_v15", False, "user", "password"
SoapRequest.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
sSOAPAction = "https://test.mpay24.com/soap/etp/1.5/ETP.wsdl" + "SelectPayment"
SoapRequest.setRequestHeader "SOAPAction", sSOAPAction
SoapRequest.send soapEnvelope
myResponseText = SoapRequest.responseText
responseText is:
"SOAP-ENV:ClientMethod 'etp:SelectPayment' not implemented: method name or namespace not recognized"
I think my
SoapRequest.setRequestHeader "SOAPAction" is false.

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

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);
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

Sending a 'application/soap+xml' SOAP request using Classic ASP

Any help with this would be appreciated; I've been at it for a few days now.
Below is the code that I've got so far; unfortunatly when I run it I get a HTTP 415 error; Cannot process the message because the content type 'text/xml; charset=UTF-8' was not the expected type 'application/soap+xml; charset=utf-8'.
I have to send the content-type of application/soap+xml as this is the only type that the web service allows; and I have to do it in classic ASP.
I've tried changing the 'send' line to "objRequest.send objXMLDoc.XML" but this then gives me a HTTP 400 Bad Request error.
strXmlToSend = "<some valid xml>"
webserviceurl = "http://webservice.com"
webserviceSOAPActionNameSpace = "avalidnamespace"
Set objRequest = Server.createobject("MSXML2.XMLHTTP.3.0")
objRequest.open "POST", webserviceurl, False
objRequest.setRequestHeader "Content-Type", "application/soap+xml"
objRequest.setRequestHeader "CharSet", "utf-8"
objRequest.setRequestHeader "action", webserviceSOAPActionNameSpace & "GetEstimate"
objRequest.setRequestHeader "SOAPAction", webserviceSOAPActionNameSpace & "GetEstimate"
Set objXMLDoc = Server.createobject("MSXML2.DOMDocument.3.0")
objXMLDoc.loadXml strXmlToSend
objRequest.send objXMLDoc
set objXMLDoc = nothing
Here's what I've used successfully in the past:
Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")
xmlhttp.open "POST", url, false
xmlhttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
xmlhttp.setRequestHeader "SOAPAction", "http://www.mydomain.com/myaction"
xmlhttp.send postdata
xml = xmlhttp.responseText
When you pass an XML DOM ot the send method the Content-Type is always set to "text/xml".
If you want to control the content type then you must pass a string. Don't bother loading the XML string into a DOM only to call the xml property since that may change the content of the xml declaration. BTW what does the xml declaration look like in the XML string and are you certain that the xml is correct? The encoding on the xml declare if present should say "UTF-8".
Don't send a header CharSet it means nothing, CharSet is an attribute of the Content-Type header.
Don't use XMLHTTP from inside ASP its not safe.
Hence your code ought to look like this:-
strXmlToSend = "<some valid xml>"
webserviceurl = "http://webservice.com"
webserviceSOAPActionNameSpace = "avalidnamespace"
Set objRequest = Server.Createobject("MSXML2.ServerXMLHTTP.3.0")
objRequest.open "POST", webserviceurl, False
objRequest.setRequestHeader "Content-Type", "application/soap+xml; charset=UTF-8"
objRequest.setRequestHeader "action", webserviceSOAPActionNameSpace & "GetEstimate"
objRequest.setRequestHeader "SOAPAction", webserviceSOAPActionNameSpace & "GetEstimate"
objRequest.send strXmlToSend
Not sure about that "action" header either looks superflous to me. Perhaps this will still fail in some way but it shouldn't complain about the Content-Type header anymore.