.Net Web Service Client SoapExtension Screwed Up Response Message from Java Web Service

2.1k Views Asked by At

I tried to add a SoapExtension to my project which uses a web reference to call a Java Web Service. All my code is in .Net 4.0

I just added an empty SoapExtension

public class MyServiceSoapExtension : SoapExtension
{
    private Stream inwardStream;
    private Stream outwardStream;

    public override object GetInitializer(Type serviceType)
    {
        return serviceType;
    }

    public override object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute)
    {
        return null;
    }

    public override void Initialize(object initializer)
    {
    }

    public override Stream ChainStream(Stream stream)
    {
        outwardStream = stream;
        inwardStream = new MemoryStream();
        return inwardStream;
    }

    public override void ProcessMessage(SoapMessage message)
    {
    }
}

And I added in my client's app.config:

<system.web>
    <webServices>
        <soapExtensionTypes>
            <add type="MyServiceClient.MyServiceSoapExtension, MyServiceClient" priority="1" />
        </soapExtensionTypes>
    </webServices>
</system.web>

I believe with code above nothing is changed yet, when I ran it I got Response is not well-formed XML. an Root element is missing. exception thrown at System.Web.Services.Protocols.SoapClientType.Invoke method (I have turned on CLR debugging). If I remove the configuration in my app.config to bypass SoapExtension I can receive whatever returns from server.

I used Fiddler to trace the outgoing and responding messages, I return SOAP from server is

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <soap:Fault>
            <faultcode>soap:Client</faultcode>
            <faultstring>Unmarshalling Error: javax.xml.transform.stax.StAXResult </faultstring>
        </soap:Fault>
    </soap:Body>
</soap:Envelope>

I believe it is a valid SOAP response.

What is wrong here?

1

There are 1 best solutions below

1
On

I think its because process message method is empty. I had the exact same issue, my process message method was handling the after serialize case only and as soon as I handle the process before deserialize, everything is working fine:

case SoapMessageStage.BeforeDeserialize:
{
    Copy(wireStream, appStream);
    appStream.Position = 0;
    break;
}