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
OverthereAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zc2Commented:
Try the code like below. I did not test it, so it may have some typos, but hopefully you got the idea.
set xmlDoc = objXMLHTTP.ResponseXml
Response.Write "SOAP fault: " & xmlDoc.SelectSingleNode("//faultstring").Text

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OverthereAuthor Commented:
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

0
zc2Commented:
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
0
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

OverthereAuthor Commented:
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

0
OverthereAuthor Commented:
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
0
zc2Commented:
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.
0
OverthereAuthor Commented:
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.
0
zc2Commented:
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:
sample of a well-formed XML we should see as the content of the server's response 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
0
OverthereAuthor Commented:
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
0
OverthereAuthor Commented:
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
0
zc2Commented:
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.
0
OverthereAuthor Commented:
Thank you for being so patience...it was appreciated..
0
OverthereAuthor Commented:
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. :}
0
zc2Commented:
You are welcome!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SOAP Protocol

From novice to tech pro — start learning today.