I am trying to consume a vendor provided AXIS Web service with WCF client. The service expects to have the request/response element <TXLife>
as the root element of the SOAP body (no operation element wrapping it). I'm using the XmlSerializer because my data contract has some custom ACORD schema idiosyncrasies. For example, the server wants to see the following (...and yes, "service" is the name of the operation...):
...<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><TXLife><TXLifeRequest xmlns="">...
My client is generating the XML with the operation serialized as a wrapping element like this:
...<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><service xmlns="urn:example.servicecontract"><TXLife><TXLifeRequest xmlns="">...
With the "extra" tag indicating the operation in the request the service is not able to handle the request and errors out. If I remove the <service>
tag the Web service happily processes the request.
Unfortunately, the service also sends the response down with the unwrapped <TXLife>
tag as the root element:
...<soapenv:Body><TXLife xmlns=""><TXLifeResponse>...
My de-serializer is not handling the response properly and I get a null
object back. I assume because my client is expecting a service operation response wrapper tag and not getting one. I don't get much help from the debugger at the de-serialization level.
I was thinking about implementing the IClientMessageFormatter or even the IClientMessageInspector to modify the request/response (e.g. Remove the operation tag from the request message and add a response tag to the response message). I know the Formatter is injected as an OperationalBehavior but I'm not sure where the MessageInspector fits into the stack. Maybe I'm going about this the wrong way... Any insight or suggestions would be appreciated. Forgive me, this is my first attempt at WCF services and I'm slowly feeling my way through. Unfortunately, everything about this service seems to be "custom".
My Service Contract:
[XmlSerializerFormat]
[ServiceContract(Namespace="urn:example.servicecontract")]
public interface IPayoutServiceContract
{
[OperationContract]
TXLife service([MessageParameter(Name = "TXLife")]TXLife request);
}
A portion of the service WSDL:
<wsdl:types><schema targetNamespace="开发者_Python百科urn:Tx103Service" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><import id="tx" namespace="http://ACORD.org/Standards/Life/2" schemaLocation="../acord/TXLife2.8.92.xsd" /></schema></wsdl:types><wsdl:message name="serviceRequest"><wsdl:part element="tx:TXLife" name="acordRequest" /></wsdl:message><wsdl:message name="serviceResponse"><wsdl:part element="tx:TXLife" name="acordResponse" /></wsdl:message><wsdl:portType name="LifeWebService"><wsdl:operation name="service"><wsdl:input message="impl:serviceRequest" name="serviceRequest" /><wsdl:output message="impl:serviceResponse" name="serviceResponse" /></wsdl:operation></wsdl:portType>
Update:
I first tried using the MessageContract(isWrapped=false)
decorator on the proxy class (the interface disallows it). That did nothing. I also tried flavors of BodyStyle = WebMessageBodyStyle.Bare
, also nothing. I assume this is due to the XMLSerializer I'm using. It seems to me that there is no easy way to "decorate" my way around this issue.
BTW: My service contract, data contract, and proxy client are all in separate projects per this recommendation which sounded solid to me: blog post by Miguel Castro
Update2:
I created Request/Response wrapper classes decorated with MessageContract/MessageBodyMember tags. Now the XML is generated as expected. Still getting the null object in the response...
Update3:
The "null" objects in my response were actually present in the XML response, but not being de-serialized because the serializer was looking for them as qualified objects. I changed them to non-qualified and my objects showed up just fine after that.
Have you tried using a MessageContract with IsWrapped=false instead of using [MessageParameter]?
精彩评论