WCF - Custom Client Request / XML Response

I am trying to use an AXIS web service provider with a WCF client. The service expects the <TXLife> request / response <TXLife> to be the root element of the SOAP body (without the operation element wrapping it). I use XmlSerializer because my data contract has some specific ACORD schema specifics. 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 generates XML using an operation serialized as a packaging element as follows:

 ...<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="">... 

Using the "extra" tag indicating the operation in the request, the service cannot process the request and errors. If I remove the <service> , the web service will successfully process the request.

Unfortunately, the service also sends a response down with the deployed <TXLife> tag as the root element:

 ...<soapenv:Body><TXLife xmlns=""><TXLifeResponse>... 

My de-serializer does not handle the response correctly and I am returning a null object. I assume that my client expects a service response response wrapper tag and does not receive it. I don't get much help from the debugger at the de-serialization level.

I was thinking of implementing IClientMessageFormatter or even IClientMessageInspector to modify the request / response (for example, remove the operation tag from the request message and add the response tag to the response message). I know that Formatter is being introduced as OperationalBehavior, but I'm not sure where the MessageInspector fits on the stack. Maybe I'm wrong ... Any ideas or suggestions would be appreciated. Forgive me, this is my first attempt at serving WCF, and I'm slowly making my way. Unfortunately, everything about this service seems to be a "custom."

My service contract:

 [XmlSerializerFormat] [ServiceContract(Namespace="urn:example.servicecontract")] public interface IPayoutServiceContract { [OperationContract] TXLife service([MessageParameter(Name = "TXLife")]TXLife request); } 

Part of the WSDL service:

 <wsdl:types><schema targetNamespace="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:

At first I tried to use the MessageContract(isWrapped=false) decorator MessageContract(isWrapped=false) in the proxy class (the interface forbids it). It did nothing. I also tried the scents BodyStyle = WebMessageBodyStyle.Bare , also nothing. I assume this is due to the XMLSerializer being used. It seems to me that there is no easy way to β€œdecorate” my path around this problem.

BTW: My service contract, data contract and proxy client are in separate projects in accordance with this recommendation, which seemed solid to me: Miguel Castro's blog post

Update2:

I created request / response shell classes, decorated with MessageContract / MessageBodyMember tags. XML is now generated as expected. Still getting the null object in the response ...

Update3:

The "null" objects in my answer were actually present in the XML response, but were not de-serialized because the serializer looked for them as qualified objects. I changed them to unskilled, and after that my objects appeared very well.

+4
source share
1 answer

Have you tried using MessageContract with IsWrapped = false instead of using [MessageParameter]?

+3
source

Source: https://habr.com/ru/post/1341341/


All Articles