Solved

Classic ASP and SOAP Web Service

Posted on 2011-09-22
18
5,499 Views
Last Modified: 2012-05-12
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
Comment
Question by:Nigel_Taylor
  • 10
  • 8
18 Comments
 
LVL 32

Expert Comment

by:Big Monty
ID: 36580729
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
 

Author Comment

by:Nigel_Taylor
ID: 36581443
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
 
LVL 32

Expert Comment

by:Big Monty
ID: 36581515
Try doing a Response.Write xml.responseText

0
 

Author Comment

by:Nigel_Taylor
ID: 36581707
That gives

Object Required: 'XML'

Regards,

Nigel
0
 

Author Comment

by:Nigel_Taylor
ID: 36582317
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
 
LVL 32

Expert Comment

by:Big Monty
ID: 36582744
0
 

Author Comment

by:Nigel_Taylor
ID: 36598015
Excellent, I will test it out when i get to work in a bit and let you know the outcome.

Nigel
0
 

Author Comment

by:Nigel_Taylor
ID: 36602072
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
 

Author Comment

by:Nigel_Taylor
ID: 36708466
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 32

Expert Comment

by:Big Monty
ID: 36709757
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
 

Author Comment

by:Nigel_Taylor
ID: 36709994
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
 
LVL 32

Expert Comment

by:Big Monty
ID: 36710029
looks like all of the special non-alpha numeric characters are not being encoded. can you try writing the output without ANY stylesheet?
0
 

Author Comment

by:Nigel_Taylor
ID: 36710309
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
 
LVL 32

Expert Comment

by:Big Monty
ID: 36710388
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
 

Author Comment

by:Nigel_Taylor
ID: 36710455
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
 
LVL 32

Accepted Solution

by:
Big Monty earned 500 total points
ID: 36710524
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
 

Author Closing Comment

by:Nigel_Taylor
ID: 36710642
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
 
LVL 32

Expert Comment

by:Big Monty
ID: 36710672
excellent, glad I could help!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In previous Articles, we have discussed how we can upload a file using .asmx web service and isolated storage space. Here, in continuation to the topic, I am going to discuss how we can use WCF for the same purpose. Steps: 1.Create the silverli…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

18 Experts available now in Live!

Get 1:1 Help Now