Go Premium for a chance to win a PS4. Enter to Win

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

Classic ASP and SOAP Web Service

Hi Guys,

Please see the attached code.

When I run this nothing seems to happen and I just get a blank page returned in the browser. The WSDL that I am trying to access is

https://ws.fedexuk.net/tracking/tracking.asmx?WSDL

Im not sure if I have the right action in the RequestHeader SOAPAction.

Any help will be greatfully receive.

Regards,

Nigel


<%
Set oXmlHTTP = CreateObject("Microsoft.XMLHTTP")

oXmlHTTP.Open "POST", "https://ws.fedexuk.net/tracking/tracking.asmx?WSDL", False

oXmlHTTP.setRequestHeader "Content-Type", "application/soap+xml; charset=utf-8"
oXmlHTTP.setRequestHeader "SOAPAction", "GetConsignment"

SOAPRequest = "<?xml version='1.0' encoding='utf-8'?>"
SOAPRequest = SOAPRequest & "<soap:Envelope xmlns:soap='http://www.w3.org/2003/05/soap-envelope' xmlns:web='https://webservices.fedexuk.net/'>"
SOAPRequest = SOAPRequest &    "<soap:Header>"
SOAPRequest = SOAPRequest &      "<web:AuthHeader>"
SOAPRequest = SOAPRequest &          "<web:UserName>***</web:UserName>"
SOAPRequest = SOAPRequest &          "<web:Password>***</web:Password>"
SOAPRequest = SOAPRequest &       "</web:AuthHeader>"
SOAPRequest = SOAPRequest &    "</soap:Header>"
SOAPRequest = SOAPRequest &    "<soap:Body>"
SOAPRequest = SOAPRequest &       "<GetConsignment>"
SOAPRequest = SOAPRequest & 	    "<web:ConsignmentNumber>***</web:ConsignmentNumber>"
SOAPRequest = SOAPRequest &       "</web:GetConsignment>"
SOAPRequest = SOAPRequest &    "</soap:Body>"
SOAPRequest = SOAPRequest & "</soap:Envelope>"



  oXmlHTTP.send SOAPRequest 

Set xmlResp = oXmlHTTP.responseXML 

Set nodes = xmlResp.getElementsByTagName("returnVal")

%>
 <ul>
 <%    For Each node in nodes    %>
     <li><%=node.text%></li>
 <%    Next    %>
 </ul>

Open in new window

0
Nigel_Taylor
Asked:
Nigel_Taylor
  • 10
  • 8
1 Solution
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
what happens if you do a Response.Write oXmlHTTP.responseXML right after the Send function? You could also try viewing the source of the page to see if there is an error.
0
 
Nigel_TaylorAuthor Commented:
Thanks for the reponse.

If I do a view source of the page all I get is
<ul>
</ul>

If I do  "response.write oxmlhttp.responseXML" after the Send I get

Response object, ASP 0185 (0x80020003)
A default property was not found for the object.

Any thoughts?

Regards,

Nigel
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
Try doing a Response.Write xml.responseText

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Nigel_TaylorAuthor Commented:
That gives

Object Required: 'XML'

Regards,

Nigel
0
 
Nigel_TaylorAuthor Commented:
Okay after a bit of playing I am now getting

"soap:SenderUnable to handle request without a valid action parameter. Please supply a valid soap action."

How do I confirm what the action should be?

Nigel
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
0
 
Nigel_TaylorAuthor Commented:
Excellent, I will test it out when i get to work in a bit and let you know the outcome.

Nigel
0
 
Nigel_TaylorAuthor Commented:
Ok I am now getting the XML response back however the XML is failing to parse as the ¬ character is used to split two values in one field. How do I overcome this?

I have a stylesheet that I have created and the field that has the ¬ in I just need to replace it with a space.

Any thoughts?

Regards,

Nigel

0
 
Nigel_TaylorAuthor Commented:
Okay I have been playing in trying to get this working and am struggling....

Basically I am getting the HTML back to the screen but I am not getting the data back. I think it is down to the Xpath not being quite right.

I ahve attached code snippets that make up the pages and attahced the response from the webservice. Any help will be greatfully recievied.

Regards,

Nige
ASP PAGE

Set oXmlHTTP = CreateObject("MSXML2.ServerXMLHTTP")


oXmlHTTP.Open "POST", "https://ws.fedexuk.net/tracking/tracking.asmx", False

oXmlHTTP.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
oXmlHTTP.setRequestHeader "SOAPAction", "https://webservices.fedexuk.net/GetConsignment"

SOAPRequest = "<?xml version=""1.0"" encoding=""utf-8""?>"
SOAPRequest = SOAPRequest & "<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/"">"
SOAPRequest = SOAPRequest &    "<soap:Header>"
SOAPRequest = SOAPRequest &      "<AuthHeader xmlns=""https://webservices.fedexuk.net/"">"
SOAPRequest = SOAPRequest &          "<UserName>123</UserName>"
SOAPRequest = SOAPRequest &          "<Password>123</Password>"
SOAPRequest = SOAPRequest &       "</AuthHeader>"
SOAPRequest = SOAPRequest &    "</soap:Header>"
SOAPRequest = SOAPRequest &    "<soap:Body>"
SOAPRequest = SOAPRequest &       "<GetConsignment xmlns=""https://webservices.fedexuk.net/"">"
SOAPRequest = SOAPRequest & 	    "<ConsignmentNumber>123</ConsignmentNumber>"
SOAPRequest = SOAPRequest &       "</GetConsignment>"
SOAPRequest = SOAPRequest &    "</soap:Body>"
SOAPRequest = SOAPRequest & "</soap:Envelope>"



oXmlHTTP.send SOAPRequest


'make sure we're not getting an HTTP error
If oXmlHTTP.status <> 200 Then
	Response.Write "HTTP Status error - " & oXmlHTTP.status
	Response.End
End If



Set xml2 = Server.CreateObject("MSXML2.DOMDocument")
xml2.async = false

xml2.loadXML oXmlHTTP.responseText

'check that the XML is being parsed correctly
If xml2.parseError.errorCode <> 0 Then
	Response.Write "Parsing error - " & xml2.parseError.reason
	Response.End
End If

set xsl = Server.CreateObject("MSXML2.DOMDocument")
xsl.async = false
xsl.load(Server.MapPath("fedex-Style.xsl"))

Response.Write xml2.transformNode(xsl)

Set xml = Nothing
Set xml2 = Nothing
Set xsl = Nothing



--------------------------------------------------------------

XSL StyleSheet

<?xml version="1.0" encoding="utf-8" ?>

 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<xsl:output method="html"/>
 <xsl:template match="/">
   <html>
   <body>
     <h2>Consognment Number <xsl:value-of select="soap:Envelope/soap:Body/GetConsignmentPResponse/GetConsignmentPResult/NewDataSet/ConsignmentDetails/customerreference"/></h2>


--------------------------------------------------------------

HTML in the Browser

<html xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<body>
<h2>Fedex Track and Trace for </h2>

Open in new window

fullResponse.xml
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
is your username and password correct? what about the URL? Without access to the FedEx API for this, its going to be hard to help you as I have no info on how their system works.
0
 
Nigel_TaylorAuthor Commented:
Okay I think I might be getting somewhere...

Using the Stylesheet below I am able to  the following returned to the browser.

<?xml version="1.0" encoding="utf-8" ?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://www.w3.org/2003/05/soap-envelope">

	<xsl:template match="/">
		<html>
			<body>
				<h2>
					
						Fedex Track and Trace for <xsl:value-of select="*" />

Open in new window



<html xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<body>
<h2>
					
						Fedex Track and Trace for &lt;NewDataSet&gt;
  &lt;xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"&gt;
    &lt;xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:Locale="en-GB"&gt;
      &lt;xs:complexType&gt;
        &lt;xs:choice minOccurs="0" maxOccurs="unbounded"&gt;

          &lt;xs:element name="ConsignmentDetails"&gt;
            &lt;xs:complexType&gt;

Open in new window


Any thoughts on why this is not being returned as XML?

Regards,

Nigel
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
looks like all of the special non-alpha numeric characters are not being encoded. can you try writing the output without ANY stylesheet?
0
 
Nigel_TaylorAuthor Commented:
Yeah if I run

Response.Write xml2.text

Below is part of the response that i get back in the browser.

<NewDataSet>
  <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:Locale="en-GB">
      <xs:complexType>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
          <xs:element name="ConsignmentDetails">
            <xs:complexType>

Open in new window


So am i right in saying the XML is being returned from the webservice its the XPath with the style sheet is where my problem now is?

Also i have noticed when I do <xsl:value-of select="*" /> in the style sheet before the opening <NewDataSet> tag it prints the username and password use to connect to the webservice. Could this have any affect on why it is not read the XML as XML?

Regards,

Nigel
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
if you copy and paste the xml2.text into a seperate file with an xml extension and save it does it open up properly?
0
 
Nigel_TaylorAuthor Commented:
I think we might be getting somewhere....

If I use

xml2.loadXML ("<NewDataSet> <xs:schema id=""NewDataSet"" xmlns="""" 

Open in new window


instead of

xml2.loadXML oXmlHTTP.responseText

Open in new window


The stylesheet all works fine.

If I then change the hard coded XML to be as below so I get xy at the start of the xml the browser return the message "Parsing error - Invalid at the top level of the document. "

xml2.loadXML ("xy<NewDataSet> <xs:schema id=""NewDataSet"" 

Open in new window



I wonder if the username and password being returned at the start of the document is the cause of our problems.

Regards,

Nigel
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
if the username and password are before the xml tags, then ya, it makes sense it would blow up. i'm wondering why its being returned there. either way, you should be able to replace the string at the beginning of the returned document with a blank string and see if that works.
0
 
Nigel_TaylorAuthor Commented:
Yeah that is exactly what I have done and it is working perfectly.

Thankyou ever so much for your help it has been brilliant.

Regards,

Nigel
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
excellent, glad I could help!
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 10
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now