Solved

I need to consume a web service in classic asp

Posted on 2010-08-17
13
1,125 Views
Last Modified: 2013-11-18
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
Comment
Question by:davo_lira
  • 7
  • 6
13 Comments
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 33460549
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
 

Author Comment

by:davo_lira
ID: 33460580
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
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 33460926
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
 

Author Comment

by:davo_lira
ID: 33476533
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
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 33476568
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
 

Author Comment

by:davo_lira
ID: 33476629
i'm still getting the same error!!
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 59

Expert Comment

by:Kevin Cross
ID: 33476722
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
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 33478007
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
 

Author Comment

by:davo_lira
ID: 33599035
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
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 33599909
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
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 33604817
Try it without the Envelope and Body.
xmlResponse.selectSingleNode("//RecibeCFDResponse/RecibeCFDResult").Text

Open in new window

0
 

Author Comment

by:davo_lira
ID: 33604882
I'm gonna check it and i will reply to you as soon as i have an answer. Thank for your support.
0
 

Author Comment

by:davo_lira
ID: 33677317
Thanks for your help, now it's working!!
 I appreciate your time, sorry for the delay in mi answer.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now