Link to home
Start Free TrialLog in
Avatar of Overthere
Overthere

asked on

Retreiving SOAP FAULT messages using classical ASP

How do I retrieve the values of the SOAP Fault message to display to the user by using classical asp?
I am sending an xml document and they use SOAP authentication.
I have attached a snapshot of the message, and its a valid error message.
 I just need to retrieve and display the SOAP FAULT values.

After researching, I know I need to extract the child nodes but I can not quite it right.
I know its XML and I should be able to extract the fault string, actor and message I couldn't find what was the best way .
I am thinking in the savdoc I should  try to extract the  child node <faultstring>.
Any help appreciated.
Below is my code for sending/receiving XML etc. It works fine.
    url = "http://ws.mysite.com/test/Gateway.asmx"
    Set objXMLHTTP = server.Createobject("MSXML2.ServerXMLHTTP")
    objXMLHTTP.Open "POST", url, false
    objXMLHTTP.setRequestHeader "Content-Type", "text/xml" 
    objXMLHTTP.send xmlmsg

'get any XMLHTTP MESSAGES
   strResult= objXMLHTTP.ResponseText
   strStatus = objXMLHTTP.StatusText
   savdoc = objXMLHTTP.ResponseText

'get any SOAP FAULT MESSAGES IF THEY EXISTS AND DISPLAY TO USER

Open in new window

SoapFaultMessage.JPG
ASKER CERTIFIED SOLUTION
Avatar of zc2
zc2
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Overthere
Overthere

ASKER

I tried that and it should have worked but didn't work. Maybe error in how I load it? I posted my coding that sends the request.
I am suppose to receive back an xml document to process.
The soap envelope is in xml format. SO selecting singlenode should work.
This is my coding to send the xml and to receive an xml document back,
    url = "http://ws.mysite.com/test/Gateway.asmx"
    Set objXMLHTTP = server.Createobject("MSXML2.ServerXMLHTTP")
    objXMLHTTP.Open "POST", url, false
    objXMLHTTP.setRequestHeader "Content-Type", "text/xml" 
    objXMLHTTP.send xmlmsg
   strResult= objXMLHTTP.ResponseText
    strStatus = objXMLHTTP.StatusText

Open in new window


Perhaps after I receive it the response, I am not loading it correctly???
And therefore can select the node?
If I add the following code to the end of my sending and receiving xml, it throws error:

	 set xdDoc = Server.CreateObject("MSXML2.DOMDocument.6.0")
	 xdDoc.load(strResult)

 "Response object error 'ASP 0185 : 80020003' 

Missing Default Property 

/test.asp, line 0 

A default property was not found for the object. 

Open in new window

Did you try to print out that  strResult variable, can you see the XML response text?
If yes, and it is a well formed XML you don't need to load it to a separate xdDoc object. A XML document object should be already created for you in objXMLHTTP.ResponseXml
I will try it soon. I don't really understand why it errors when I do load using the following code.

 set xdDoc = Server.CreateObject("MSXML2.DOMDocument.6.0")
	 xdDoc.load(strResult)

Open in new window

Okay, it does and I attached the output. No very elegant to display to the user. Since it is in a xml format why doesn't it load in MSXML2,DOMDocument? Is it because it does not start with XML statement?
strResult.JPG
The strResult you posted is not XML, it is a plain text. XML was in your original post. Why those two are different?

I just tried, if the server responses with valid XML, objXMLHTTP.ResponseText does contain the XML text (with all the mark up tags, etc.) and objXMLHTTP.ResponseXML contains a loaded DOM tree object. You can convert it back to XML text by calling objXMLHTTP.ResponseXML.xml

Please make sure the server actually responds with a valid XML, not just text.
Thank you for responding.  My apologizes for the confusion.
I am not that familiar with SOAP and although it appeared to be xml, I didn't think it was because of the lack of a XML declaration as first line.
I am groping my way around this issue. I do know that the client  will send the soap authentication - validated or with authorization errors, along with the XML document In the response object.
 I am just trying to resolve it.  So from what you have explained, I think I have a better understanding.
Again, sorry for the confusion that I may have caused.
You should split this into two separate parts. First, you need to make sure, that the server actually returns a valid XML.
Second, once you sure a valid well formed XML is returned you need to extract the text message from it.

The valid XML text in the server response should be looking like this:
User generated image No extra tags and not a plain text, but XML with tags.
Please make sure that objXMLHTTP.ResponseText contains such text.

If you have problem to debug your ASP, make a test vbscript file with the same code (just replace server.Createobject() with Createobject() and response.Write with WScript.Echo ) and execute it in Windows Scripting Host as
cscript //D yourfile.vbs

Download and install a script debugger if you don't have any, you could try free edition of Microsoft visual studio https://developer.microsoft.com/en-us/windows/downloads
Okay, it's getting better. I do not know why, something has changed.
Now I am receiving a xml document. See attached screen shot.  That being so, I tried your snippet of coding and it failed.

  url = "http://ws.mysite.com/test/Gateway.asmx"
    Set objXMLHTTP = server.Createobject("MSXML2.ServerXMLHTTP")
    objXMLHTTP.Open "POST", url, false
    objXMLHTTP.setRequestHeader "Content-Type", "text/xml" 
    objXMLHTTP.send xmlmsg
    strXML = objXMLHTTP.ResponseXML.xml
    strResult= objXMLHTTP.ResponseText
    strStatus = objXMLHTTP.StatusText
	
    response.write strResult ' displays an xml doxument

Open in new window

strResult.JPG
I just saw your comment while posting. Things have improved but it doesn't make sense because all I added was
strXML = objXMLHTTP.ResponseXML.xml

Open in new window


 And my response.write still uses strResult  - BUT - the output is different - see screen shot.  And I am not doing anything with the strXML.
Thank you for the suggestions - good idea and it jogged my memory.
Now, to figure out why your snippet does not work cause it should..
again thank you.
strResult.JPG
You don't need to use objXMLHTTP.ResponseXML.xml except for debugging purposes,  it's redundant (XML text is parsed to the DOM tree, and the serialized back to text. But you already should have the text in objXMLHTTP.ResponseText).

But it looks like objXMLHTTP.ResponseXML contains a valid parsed DOM tree now, right? So we can proceed to the step 2. Please see my very first comment.
Thank you for being so patience...it was appreciated..
Thank you so much - its works! I have no clue what changed - it wasn't the coding - gremlins???
And thank you for helping to educate me. It has been appreciated. :}
You are welcome!