Chris Gessler
Chris Gessler

Reputation: 23113

Altering a SOAP message before deserialization

I'm having trouble intercepting a response message due to an invalid envelope. Unfortunately, WCF is throwing the exception "Unrecognized message version." before AfterReceiveReply is called so I don't have an opportunity to correct the response XML. Is there a lower level (or different) call I can use to intercept the stream and correct this XML or is there a better way to handle the response, i.e. CustomBinding?

I've tried IClientMessageInspector AfterReceiveReply and IOperationBehavior but these behaviors are both called after the exception is thrown.

Here's what the response looks like.

<ENVELOPE>
    <HEADER>
        <ERROR_CODE>955</ERROR_CODE>
        <ERROR_DESC>XML Parsing Failed: test:1:74 error:  value '1231231230' does not match regular expression facet '\d{19,20}'</ERROR_DESC>
        <ASYNCH_RESPONSE_INDICATOR>0</ASYNCH_RESPONSE_INDICATOR>
    </HEADER>
    <BODY>
        <MY_METHOD_RESPONSE></MY_METHOD_RESPONSE>
    </BODY>
</ENVELOPE>

Upvotes: 1

Views: 506

Answers (1)

tom redfern
tom redfern

Reputation: 31750

The service you are trying to call is not a SOAP service. It looks like an old style POX web service, in which case there are two ways you can consume it.

  1. use a WCF POX client, or
  2. use HttpWebRequst

To use WCF, refer to here and here. Your problem here is that these style of services are now considered unorthodox, so the later versions of WCF may no longer support them.

On the other hand, HttpWebRequest, while still supported in .net, is fiddly and not widely used. It does have a high-level wrapper called WebClient which is much easier to use, but it may not give you the level of control you need.

I would certainly investigate the second option first. The support for POX services in WCF was brought in in 2008 with the REST Toolkit, Microsoft's initial foray into the world outside SOAP services (.net remoting notwithstanding), and so is seriously dated.

Upvotes: 1

Related Questions