Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF Message formatting

I recently re-wrote a WCF service for a client. Their previous service was on .NET 3.5 and I cleaned up the code and upgraded to 4.5.2.

Functionally, the service works, but I'm having trouble with some aspects of the message format not matching up.

When I use the WCF service client to test the service, I get a message with the following structure:

<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope">
  <s:Header>
    <a:Action s:mustUnderstand="1">http://XXXXX.com/XXXXX/service/v1_0/IXXXXXInterfacePort/GetRates</a:Action>
    <a:MessageID>urn:uuid:071db031-f492-42f5-89e6-fb4a321c81c9</a:MessageID>
    <a:ReplyTo>
      <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
    </a:ReplyTo>
  </s:Header>
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <GetRatesIP xmlns="http://XXXXX.com/XXXXX/service/v1_0">
      <ShipmentHeader xmlns="">
        <ShipmentID>XXXXX</ShipmentID>
        <Zipcode>XXXXX</Zipcode>
      </ShipmentHeader>
      <ShipmentItemsList xmlns="">
        <ShipmentItems>
          <quantity>10</quantity>
          <sku>XXXXX</sku>
          <freeShipping>true</freeShipping>
        </ShipmentItems>
      </ShipmentItemsList>
    </GetRatesIP>
  </s:Body>

But when the client puts the service into test, the message structure coming from the client looks like this:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
	<soap:Body>
		<GetRatesIP xmlns="http://XXXXX.com/XXXXX/service/v1_0">
			<ShipmentHeader xmlns="">
				<ShipmentID>XXXXX</ShipmentID>
				<Zipcode>XXXXX</Zipcode>
			</ShipmentHeader>
			<ShipmentItemsList xmlns="">
				<ShipmentItems>
					<quantity>10</quantity>
					<sku>XXXXX</sku>
				</ShipmentItems>
			</ShipmentItemsList>
		</GetRatesIP>
	</soap:Body>
</soap:Envelope>

Data wise, everything seems OK. My version has a free shipping attribute, but from what I can see this is treated as optional by the service and should be OK if it is missing. At any rate, the client claims that even though it's in the code the value has never been sent by the service client, even though it's mentioned in their code.

My guess is that the service is having trouble with the "soap:Envelope ..." style versus the "s:Envelope ..." style. I used the exact same service contracts. The existing code was using the XML serializer as opposed to the data contract serializer, but again I copied the attributes (Serializable, XmlType, XmlArray, XmlArrayItem, etc.) and the MessageContract attributes exactly from the existing code. Looked at the config on the server, nothing looked wrong there. Working on getting the client side config, but not expecting it to shed any light.

Anybody have any idea what could be going on here? I've been (and will continue) to look on the Internet, but I'm not finding an answer. My luck, it's some weird, obscure flag set somewhere in the bowls of Visual Studio/WCF that just need to be flipped.

Thanks, James

like image 839
James Bender Avatar asked Apr 10 '26 14:04

James Bender


2 Answers

Your test uses SOAP 1.2 (http://www.w3.org/2003/05/soap-envelope) with WS-Addressing (the header entries a:Action, a:MessageID, ...) whereas the client uses SOAP 1.1 (http://schemas.xmlsoap.org/soap/envelope/).

This is a binding issue. If you want the client to stay as it is, change the binding on your service side.

like image 85
nodots Avatar answered Apr 12 '26 08:04

nodots


Change the binding from WSHttpBinding(Default SOAP 1.2) to use BasicHttpBinding( default to 1.1)

Or you can forcibly change the soap version used by BasicHttpBinding to use SOAP 1.2 by

`<textMessageEncoding messageVersion="Soap12" />` 

in customBindingConfig section.

like image 44
NatarajC Avatar answered Apr 12 '26 08:04

NatarajC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!