Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1183
  • Last Modified:

I need to consume a web service in classic asp

Hi

I need to consume a webservice using classic asp. Here is a sample SOAP Request AND Response. I've trying in some ways, but i still cannot work it out. Actually i can connect it but i don't know how to get the response. Any code tha could help me to send request and get the response it's accepted.

Thanks for your help

Request:
-------------------------------------------------------------------------------------------------------------------
POST /integracion/recibecfd/wseDocRecibo.asmx HTTP/1.1
Host: www2.soriana.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.sci-grupo.com.mx/RecibeCFD"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <RecibeCFD xmlns="http://www.sci-grupo.com.mx/">
      <XMLCFD>string</XMLCFD>
    </RecibeCFD>
  </soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

Response:
-------------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <RecibeCFDResponse xmlns="http://www.sci-grupo.com.mx/">
      <RecibeCFDResult>string</RecibeCFDResult>
    </RecibeCFDResponse>
  </soap:Body>
</soap:Envelope>
0
davo_lira
Asked:
davo_lira
  • 7
  • 6
1 Solution
 
Kevin CrossChief Technology OfficerCommented:
What are you using to connect to it ? In other words, what version of MSXML or otherwise library you are using ... please post the code if you are unsure.

Here is an old reference using SOAP client.

http://www.c-sharpcorner.com/UploadFile/ankithakur/WSIntegration02132006041221AM/WSIntegration.aspx

I used MSXML in an old ASP app we had that I can still get to code for as a sample for you ... so please confirm which you are using.
0
 
davo_liraAuthor Commented:
I am using this command for creating object:
Server.CreateObject("MSXML2.XMLHTTP"). I think that your example coul help me, i you need my code still, please tell me and i will post it
0
 
Kevin CrossChief Technology OfficerCommented:
Sorry for the delay, but here is some sample code -- have cleaned a bit to remove private data but should give you the gist of how the MSXML request | response works.
' setup the request XML string|object
Set xmlDoc = Server.CreateObject("MSXML2.DOMDocument")
xmlStr = "<?xml version=""1.0"" encoding=""utf-8""?>"
xmlStr = xmlStr & "<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">"
xmlStr = xmlStr & "<soap:Body>"
xmlStr = xmlStr & "<OperationName xmlns=""http://your.op.namespace/"">"
xmlStr = xmlStr & "<Parameter>" & someParam & "</Parameter>"
xmlStr = xmlStr & "</OperationName></soap:Body></soap:Envelope>"
xmlDoc.loadXML(xmlStr)

' create XMLHTTP object to handle ws consumption
Set xmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
Dim lResolve, lConnect, lSend, lReceive
' time values that can be set for XMLHTTP
lResolve = 5 * 1000
lConnect = 5 * 1000
lSend = 15 * 1000
lReceive = 180 * 1000
xmlHttp.setTimeouts lResolve, lConnect, lSend, lReceive

xmlHttp.open "POST", "http://the.web.service.url", False
xmlHttp.setRequestHeader "Content-type", "text/xml; charset=utf-8"
xmlHttp.setRequestHeader "SOAPAction", "http://the.web.service.url/OperationName" 
xmlHttp.send xmlDoc.xml 'add XML doc to request

Set xmlDocOut = Server.CreateObject("MSXML2.DOMDocument")
xmlDocOut.async = false
' get response using XMLHTTP responseXML property
xmlDocOut.loadXML(xmlHttp.responseXML.xml)

Open in new window

0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
davo_liraAuthor Commented:
I try what you told me but is not working yet. I really need to consume this web service as soon as possible, please help me.

This is the link for webservice:
http://www2.soriana.com/integracion/recibecfd/wseDocRecibo.asmx

Here is what i'm doing:


		Set xmlhttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
		xmlhttp.Open "GET", strURL, false
		xmlhttp.setRequestHeader "Man", "GET " & strURL & " HTTP/1.1"
		xmlhttp.setRequestHeader "Host", "www2.soriana.com"
		xmlhttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
		xmlhttp.setRequestHeader "SOAPAction", strSOAPAction
		xmlhttp.send (strSoap)
		If xmlhttp.Status = 200 Then
			blnSuccess = "OK"
			Set xmlResponse = Server.CreateObject("MSXML2.DOMDocument") 
		        xmlResponse.Async=False
			xmlResponse.loadXML(xmlhttp.responseText)
			blnSuccess = blnSuccess & xmlResponse.selectSingleNode("/soap:Envelope/soap:Body/RecibeCFDResponse/RecibeCFDResult").Text
			Set xmlResponse = Nothing
		Else
			blnSuccess = "NOT|"&xmlhttp.Status&"|"&xmlhttp.statustext
		End If

I got this error:

Microsoft VBScript Error '800a01a8'

Object Required: 'xmlResponse.selectSingleNode(...)' 

Open in new window

0
 
Kevin CrossChief Technology OfficerCommented:
Notice I used "xmlDocOut.loadXML(xmlHttp.responseXML.xml)" and you are using "xmlResponse.loadXML(xmlhttp.responseText)". Try changing line 12 to:
xmlResponse.loadXML(xmlhttp.responseXML.xml)

Open in new window

0
 
davo_liraAuthor Commented:
i'm still getting the same error!!
0
 
Kevin CrossChief Technology OfficerCommented:
Okay, I didn't scroll over.

xmlResponse.selectSingleNode("/soap:Envelope/soap:Body/RecibeCFDResponse/RecibeCFDResult").Text

Since you are using the resulting node as an object, you may be getting error because of the .Text piece. Let me look as to not rely on my poor memory. :)
0
 
Kevin CrossChief Technology OfficerCommented:
Okay, sorry about the delay, had some day job things to tend to like meetings. At any rate, I just double checked old code to refresh my memory and the selectSingleNode(...) method is not directly on the DOMDocument from response but rather a member of documentElement; therefore, the code would look something like this:

Set xmlNode = xmlResponse.documentElement.selectSingleNode("//RecibeCFDResponse/RecibeCFDResult")
blnSuccess = blnSuccess & xmlNode.Text

Give that a try -- although, if blnSuccess is truly a boolean like the name would suggest, you probably don't want to put the text into that variable. However, I do notice you putting text in that field elsewhere so maybe it is just my being use to that naming convention to signify a success status flag. Would expect something like strMessage or strStatus for the functionality it appears you to be using blnSuccess for...
0
 
davo_liraAuthor Commented:
Hi

i'm still with problems, i'm sorry for the delay, i've been working in other stuff about the same system. My problem is that i need to send an xml document converted to string through a webservice, and webservice returns me a message that contains the result of my request. This answer is returned as a string, but it is also and XML message.
I've been searching for different solutions using ASP, but actually nothing is working well and the fact is that i really need to USE ASP, i think that i'm doing something wrong, but trying with some many options got me confused. I get from MSXML2 object that my SOAP request actually gets the connection, but when i try to get result message i can't see what i'm expected, actually i see in my response this page content (Exactly the same that page shows):

http://www2.soriana.com/Integracion/RecibeCFD/wseDocRecibo.asmx?op=RecibeCFD

If you have any example that you think could work for this process i'll test it and it would be very helpful to me.

Thanks again.
David.

(I put again all webservice)


REQUEST:
-------------------------------------------------------------------
POST /Integracion/RecibeCFD/wseDocRecibo.asmx HTTP/1.1
Host: www2.soriana.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.sci-grupo.com.mx/RecibeCFD"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <RecibeCFD xmlns="http://www.sci-grupo.com.mx/">
      <XMLCFD>string</XMLCFD>
    </RecibeCFD>
  </soap:Body>
</soap:Envelope>
-------------------------------------------------------------------

RESPONSE
-------------------------------------------------------------------
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <RecibeCFDResponse xmlns="http://www.sci-grupo.com.mx/">
      <RecibeCFDResult>string</RecibeCFDResult>
    </RecibeCFDResponse>
  </soap:Body>
</soap:Envelope>

Open in new window

0
 
Kevin CrossChief Technology OfficerCommented:
The code example I gave you is working in a live application written in ASP, so it is possible using that method; therefore, I will have to look up the error message you are getting and see if I can determine the issue ...
0
 
Kevin CrossChief Technology OfficerCommented:
Try it without the Envelope and Body.
xmlResponse.selectSingleNode("//RecibeCFDResponse/RecibeCFDResult").Text

Open in new window

0
 
davo_liraAuthor Commented:
I'm gonna check it and i will reply to you as soon as i have an answer. Thank for your support.
0
 
davo_liraAuthor Commented:
Thanks for your help, now it's working!!
 I appreciate your time, sorry for the delay in mi answer.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now