views:

126

answers:

3

Hello,

I am trying to get a WCF .Net 4.0 client to work with a NuSOAP/0.7.2 (1.94) Web Service. First thing, the web service is not based on current SOA standards so I had to create a custom encoder to handle the ISO-8859-1 message encoding. When I get the response, WCF throws the following exception

"Error in deserializing body of reply message"

When looking at the SOAP body, I see <SOAP-ENV:Body>... stream ...</SOAP-ENV:Body>

Has anyone come across this error? Any feedback or a point in the right direction would greatly be appreciated. This is my first WCF to "non" WCF service.

ApplicationData
TraceData
<DataItem>
<MessageLogTraceRecord Time="2010-07-14T19:14:36.4832868-07:00" Source="TransportReceive" Type="System.ServiceModel.Channels.StreamedMessage" xmlns="http://schemas.microsoft.com/2004/06/ServiceModel/Management/MessageTrace"&gt;
<HttpResponse>
<StatusCode>OK</StatusCode>
<StatusDescription>OK</StatusDescription>
<WebHeaders>
<X-SOAP-Server>NuSOAP/0.7.2 (1.94)</X-SOAP-Server>
<Content-Encoding></Content-Encoding>
<Content-Length>496</Content-Length>
<Content-Type>text/xml; charset=ISO-8859-1</Content-Type>
<Date>Thu, 15 Jul 2010 02:14:36 GMT</Date>
<Server>Apache/2.0.54 (Unix) mod_ssl/2.0.54 OpenSSL/0.9.7a PHP/4.3.11</Server>
<X-Powered-By>PHP/4.3.11</X-Powered-By>
</WebHeaders>
</HttpResponse>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="https://www.datatranswebedi.com/soapv2/"&gt;
<SOAP-ENV:Header></SOAP-ENV:Header>
<SOAP-ENV:Body>... stream ...</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
</MessageLogTraceRecord>
</DataItem>
</TraceData>
</ApplicationData>

Thanks in advance, Brennan

+1  A: 

I had to do the same thing (against another legacy type webservice) and I ran into issues at first.

I came across this excellent blog post WCF: Text Message Encoding and ISO-8859-1 Encoding which describes a few pitfalls when implementing a custom text encoder for WCF - maybe that'll be helpful to you?

Also check out a previous Stackoverflow question on the same topic:

http://stackoverflow.com/questions/1908030/calling-a-webservice-that-uses-iso-8859-1-encoding-from-wcf

marc_s
A: 

It turns there was an error in deserializing the date because it was not in the proper format. I caught the error be enabling "Verbose" debug mode in the WCF client.

System.InvalidCastException: Cannot assign object of type System.Xml.XmlNode[] to an object of type System.DateTime.

The legacy web service was passing back "xsd:date" with a date and time when the data type should have been "xsd:dateTime".

To confirm this was the cause of the problem, I requested two records from the web service and manipulated the XML in the override Message ReadMessage() method and changed the auto generated proxy class. This corrected the problem and I know this not the final solution. Before I contact the author of the legacy web service, does anyone having any comments on the Soap date and dateTime format?

Maybe the following date is valid in Soap Version 1.1 with ISO-8859-1 encoding:

<date xsi:type="xsd:date">2010-05-02 08:03:45</date>

 If it is, is this an issue using a custom encoder or was it really the date type/format in the soap body? Microsoft only accepted that date in the following format:

<date xsi:type="xsd:dateTime">2010-05-02T08:03:45</date>


    <customBinding>
      <binding name="ISO8859Binding">
        <customTextMessageEncoding messageVersion="Soap11" encoding="ISO-8859-1" mediaType="text/xml"  />
        <httpsTransport />
      </binding>
      </customBinding>

public override Message ReadMessage(Stream stream, int maxSizeOfHeaders, string contentType)
{

    XmlReader reader = XmlReader.Create(stream);
    XmlDocument doc = new XmlDocument();

    // Log to a file.
    StreamWriter sw = new StreamWriter(@"C:\dump2.txt");

    doc.Load(reader);
    doc.InnerXml = doc.InnerXml.Replace("xsd:date", "xsd:dateTime");
    doc.InnerXml = doc.InnerXml.Replace("2010-05-02 08:03:45", "2010-05-02T08:03:45");
    doc.InnerXml = doc.InnerXml.Replace("2010-05-02 12:38:06", "2010-05-02T12:38:06");

    sw.WriteLine(doc.InnerXml);
    sw.Flush();
    sw.Close();

    byte[] buffer = System.Text.Encoding.Default.GetBytes(doc.InnerXml);
    Stream test = new MemoryStream(buffer);
    XmlReader reader2 = XmlReader.Create(test);

    return Message.CreateMessage(reader2, maxSizeOfHeaders, this.MessageVersion);

}

Thanks Again, Brennan

Brennan Mann
A: 

You answered your own question.

Grand Master T