D Tyler
D Tyler

Reputation: 11

How to handle inbound xml requests with web service using ASP

I write code everyday using standard HTML & classic ASP. I have been asked to build a small API which will use our ASP/html platform and SQL Server database. I have no trouble dealing with the ASP/SQL Server, HTML etc. I can even write XML requests to query our servers. But I have no idea where to start in setting up a service to "listen" for inbound XML requests. I have prepared about a dozen request/response routines, but do not know how to code the page that receives that request.

Can anyone out there offer a hand?

For example:

One of our methods/functions for them to request is a simple Category List request. Using SOAP, I can make the request just fine, It is just that I do not know how to form the receiving side at server to entertain the request and respond.

I have made the request below, I just need to know how to handle the web service page to receive this request and respond with the data. Any help would be greatly appreciated. Please see below.

VARs to send

DealerID
UserID
Password
Dept

Code:

DIM wagConnect, WAGRequest
wagConnect = "http://www....../catreq.asp"

Dim strResult, strNamespace, strFunction
DIM wagResponse, xmldom, xmlresponse
Dim objXMLHTTP : set objXMLHTTP = Server.CreateObject("Msxml2.XMLHTTP.3.0")

' strNamespace="urn:externalwsdl"
' strFunction="add_line"
' area_code

WAGRequest = "<?xml version=""1.0"" encoding=""utf-8"" ?>" & _
             "<soapenv:Envelope xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/"">" & _
             "<soapenv:Body>" & _
             "<Get_Categories xmlns=""urn:externalwsdl"">" & _
             "<DealerInfo>" & _
             "<DealerID>DealerTest</DealerID>" & _
             "<UserID>K850</UserID>" & _
             "<Password>1234567Pass</Password>" & _
             "</DealerInfo>" & _
             "<CatInfo>" & _
             "<Dept></Dept>" & _
             "</CatInfo>" & _
             "</Get_Categories>" & _
             "</soapenv:Body>" & _
             "</soapenv:Envelope>"

objXMLHTTP.open "POST", "" & wagConnect & "", False
objXMLHTTP.setRequestHeader "Content-Type", "text/xml; charset=UTF-8"
objXMLHTTP.setRequestHeader "Content-Length", Len(WAGRequest)
'objXMLHTTP.setRequestHeader "SOAPMethodName", strFunction
objXMLHTTP.setRequestHeader "SOAPAction", wagConnect
'strNamespace & "#" & strFunction

'send the request and capture the result
Call objXMLHTTP.send(WAGRequest)

xmlresponse = objXMLHTTP.responsetext

wagResponse = ("<pre>"& replace(replace(xmlresponse, "<", "&lt;"), ">", "&gt;<br>") &"</pre>")

Set xmldom = Server.CreateObject("Microsoft.XMLDOM")
xmldom.async = false
xmldom.loadxml(objXMLHTTP.responsexml.xml)

IF objXMLHTTP.status <> 200 THEN 
   wagResponse = "Could not get XML data."
END IF

'Response elements and attributes

'Result-Code (1 = Success, 0 = Failed)
'Category Count {Cat_Count, int} (Number of Categories returned)
'Category
'Child elements:    'CatName {Cat_Name, nvarchar} (Short Text)
'Category Subtitle {Cat_Desc, nvarchar} (SubTitle)
'Category Desc {Cat_Memo, ntext} (long description)
'Picture URL {Cat_Pic, ntext} (URL)'

'ResultCode = xmldom.getElementsByTagName("result-code")(0).text

If ResultCode = 1 THEN
   CatCnt = xmldom.getElementsByTagName("Cat_Count")(0).text
   CatName = xmldom.getElementsByTagName("Cat_Name")(0).text 
   CatDesc = xmldom.getElementsByTagName("Cat_Desc")(0).text 
   CatMemo = xmldom.getElementsByTagName("Cat_Memo")(0).text 
   CatPic = xmldom.getElementsByTagName("Cat_Pic")(0).text 
End if

Thanks for your help!

Upvotes: 1

Views: 424

Answers (1)

Vahid Mafi
Vahid Mafi

Reputation: 111

You should simply make a script which gets instructions by POST in xml format. Then the script should retrive the its variables from posted xml content and then generate an xml output and sent it easily by response.write()

Upvotes: 1

Related Questions