[Javascript] problem with ResponseXml.

K

KaNos

Hello aspx world,
I consume a webservice with Javascript functions.
But the response is ok and, very strange, document is null.
How to resolve this problem thanks ??????



xmlHttpRequest.open("POST", myAddressLocation, false);
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.send(xmldocumentSoapRequest);
if (xmlHttpRequest.readyState == 4)
{
alert(xmlHttpRequest.responseText); // response ok

var xmldocumentSoapResponse = xmlHttpRequest.responseXML;

alert(xmldocumentSoapResponse.documentElement == null); // response is
true ?
}

The well formed webservice response with responseText.

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<InitializeResponse xmlns="http://www.euristyle.com/">
<InitializeResult>
<cocd xmlns="http://ltsc.ieee.org/xsd/1484_11_3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ltsc.ieee.org/xsd/1484_11_3ieee_1484_11_3_2005.xsd">
<commentsFromLearner/>
<commentsFromLMS/>
<completionStatus>unknown</completionStatus>
<completionThreshold/>
<credit>credit</credit>
<entry>ab_initio</entry>
<exit/>
<interactions/>
<launchData/>
<learnerId>1234567890</learnerId>
<learnerName>My</learnerName>
<learnerPreferenceData>
<audioCaptioning>no_change</audioCaptioning>
<audioLevel>1</audioLevel>
<deliverySpeed>1</deliverySpeed>
<language>fr-FR</language>
</learnerPreferenceData>
<location/>
<maxTimeAllowed/>
<mode>normal</mode>
<objectives/>
<progressMeasure/>
<scaledPassingScore/>
<score/>
<sessionTime/>
<successStatus>unknown</successStatus>
<suspendData/>
<timeLimitAction>continue_no_message</timeLimitAction>
<totalTime>PT0S</totalTime>
<dataModelVersion>1.0</dataModelVersion>
</cocd>
</InitializeResult>
</InitializeResponse>
</soap:Body>
</soap:Envelope>
 
M

Martin Honnen

KaNos wrote:

xmlHttpRequest.open("POST", myAddressLocation, false);
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.send(xmldocumentSoapRequest);
if (xmlHttpRequest.readyState == 4)
{
alert(xmlHttpRequest.responseText); // response ok

var xmldocumentSoapResponse = xmlHttpRequest.responseXML;

alert(xmldocumentSoapResponse.documentElement == null); // response is
true ?

Check xmlHttpRequest.getAllResponseHeaders(), what does that show, in
particular for the HTTP Content-Type header?
And if that is script with IE then check
xmlHttpRequest.responseXML.parseError.errorCode
If that is not 0 then check
xmlHttpRequest.responseXML.parseError.reason
 
K

KaNos

Hello Martin,
The HTTP Header is :

Server: Microsoft-IIS/5.1
Date: Tue, 08 Aug 2006 15:54:04 GMT
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Cache-Control: private, max-age=0
Content-Type: application/soap+xml; charset=utf-8
Content-Length: 1289

And xmlHttpRequest.responseXML.parseError.errorCode is 0. So i think no
error.
Where is my problem ?
Thanks,
 
K

KaNos

Hello Martin,
The HTTP Header is :

Server: Microsoft-IIS/5.1
Date: Tue, 08 Aug 2006 15:54:04 GMT
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Cache-Control: private, max-age=0
Content-Type: application/soap+xml; charset=utf-8
Content-Length: 1289

And xmlHttpRequest.responseXML.parseError.errorCode is 0. So i think no
error.
Where is my problem ?
Thanks,
 
M

Martin Honnen

KaNos wrote:

The HTTP Header is :

Server: Microsoft-IIS/5.1
Date: Tue, 08 Aug 2006 15:54:04 GMT
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Cache-Control: private, max-age=0
Content-Type: application/soap+xml; charset=utf-8
Content-Length: 1289

And xmlHttpRequest.responseXML.parseError.errorCode is 0. So i think no
error.
Where is my problem ?

I think the problem is
Content-Type: application/soap+xml
which is probably technically correct but not recognized by
MSXML/XMLHttpRequest as an XML MIME type, it only looks for
application/xml or text/xml to decide whether to populate responseXML.

So you either need to change the server to send the generic XML
Content-Type application/xml or you need to try to solve that on the
client where with MSXML/IE you could do e.g.
xmlHttpRequest.responseXML.load(xmlHttpRequest.responseBody)
when you receive the response.

With Mozilla you can do
xmlHttpRequest.overrideMimeType('application/xml')
before you send the request to convince it to parse the response as XML
into the responseXML object even if the Content-Type the server sends is
not recognized as an XML MIME type.
 
K

KaNos

Great Martin,
I've developed the webservice in C# with DotNet V2. Do uou know how can
i do to change the XML MIME type directly in the webservice source code ?
Real Thanks,
 
M

Martin Honnen

KaNos wrote:

I've developed the webservice in C# with DotNet V2. Do uou know how can
i do to change the XML MIME type directly in the webservice source code ?

If your class implementing the web service inherits from the WebService
class then in the web service methods I think it should be possible to
do e.g.
Context.Response.ContentType = "application/xml";
I haven't tried that however. Let us know whether that approach works
for you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,086
Latest member
ChelseaAmi

Latest Threads

Top