Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Call a .Net Web Service Method from Classic ASP Using SOAP

I am trying to call a .Net Web Service from Classic ASP using SOAP. I have built the following code as a test and keep getting back an empty reponsebody with a 400 Bad Request error. Am I doing something wrong or might this issue be on the .Net side?

'set up xmlhttp to checkout server
Dim oRequest
Set oRequest = Server.CreateObject("MSXML2.ServerXMLHTTP")

'setting this option will allow ServerXMLHTTP to ignore the certificate errors it encounters.
oRequest.setOption(2) = SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS


' resolve, connect, send, receive - in milliseconds
oRequest.setTimeouts 10000, 10000, 10000, 10000

'set the URL
msURL = "[redacted]"

msSOAP = "<?xml version=""1.0"" encoding=""utf-8"" ?>"
msSOAP = msSOAP & "<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"">"
msSOAP = msSOAP & "<SOAP:Body>"
msSOAP = msSOAP & "<[Some Service] xmlns=""http://localhost"">"
msSOAP = msSOAP & "<MethodName>"
msSOAP = msSOAP & "<methodParam1>[some value]</methodParam1>"
msSOAP = msSOAP & "<methodParam2>[some value]</methodParam2>"
msSOAP = msSOAP & "<methodParam3>[some value]</methodParam3>"
msSOAP = msSOAP & "</MethodName>"
msSOAP = msSOAP & "</[Some Service]>"
msSOAP = msSOAP & "</SOAP:Body>"
msSOAP = msSOAP & "</soap12:Envelope>"

oRequest.Open "POST", msURL, False
oRequest.setRequestHeader "Content-Type", "text/xml"
oRequest.setRequestHeader "SOAPMethodName", "[MethodName]"
oRequest.setRequestHeader "SOAPAction", "[Some Url]"
oRequest.send msSOAP

Response.Write oRequest.ResponseBody
like image 321
crackedcornjimmy Avatar asked Jul 21 '11 19:07

crackedcornjimmy


1 Answers

The following solution was the answer to my problem. And Filburt, once I actually made a good SOAP call, I discovered that you're question was highly legitimate. The type and format mattered greatly!

'set up xmlhttp to checkout server
Dim oRequest
Set oRequest = Server.CreateObject("MSXML2.ServerXMLHTTP")

'setting this option will allow ServerXMLHTTP to ignore the certificate errors it encounters.
oRequest.setOption(2) = SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS

' resolve, connect, send, receive - in milliseconds
oRequest.setTimeouts 10000, 10000, 10000, 10000

'set the URL
msURL = "[Service Url]"

msSOAP = "<?xml version=""1.0"" encoding=""utf-8"" ?>"
msSOAP = msSOAP & "<s:Envelope xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/"">"
msSOAP = msSOAP & "<s:Body>"
msSOAP = msSOAP & "<[MethodName] xmlns=""[Some Namespace]"">"
msSOAP = msSOAP & "<methodParam1>[Some value]</methodParam1>"
 msSOAP = msSOAP & "<methodParam2>[Some value]</methodParam2>"
 msSOAP = msSOAP & "<methodParam3>[Some value]</methodParam3>"
   msSOAP = msSOAP & "</MethodName>"
msSOAP = msSOAP & "</s:Body>"
msSOAP = msSOAP & "</s:Envelope>"

oRequest.Open "POST", msURL, False
oRequest.setRequestHeader "Content-Type", "text/xml"
oRequest.setRequestHeader "SOAPAction", "[Some Url]"
oRequest.send msSOAP

I took the "?wsdl" off of the url and changed the envelope a bit and it works now. I also removed the setting of the SoapMethodName header.

like image 60
crackedcornjimmy Avatar answered Nov 15 '22 11:11

crackedcornjimmy