3

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

James Bender
  • 1,175
  • 1
  • 11
  • 22
  • On the client side does the class that contains the `freeShipping` property also contain a property `freeShippingSpecified`. If yes, set that property to true and try again. – Amith Sewnarain Apr 01 '16 at 20:26
  • It does not. I inherited this and nobody who was around when it was written is around anymore. It looks like the server has a specification for free shipping, but it's not required and not always sent. The design of the service is a little weird and not how *I* would have done it, but I'm not allowed to change the message format, so... :( – James Bender Apr 02 '16 at 18:34

3 Answers3

2

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.

nodots
  • 1,450
  • 11
  • 19
1

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.

NatarajC
  • 123
  • 6
  • Sorry, was on vacation last week, just saw this now. Just to clarify; the app.config in my service library is using basicHttpBinding and the web.config on my website doesn't have a binding at all. So, does WCF default to WSHttpBinding and that's my problem? If I add an endpoint to the web.config that should fix it? I'm asking because I need the clients interaction to do this and I don't want to interrupt him too much without having all the details. – James Bender Apr 12 '16 at 12:51
  • May be this will help http://stackoverflow.com/questions/6263813/what-is-the-default-wcf-binding – NatarajC Apr 12 '16 at 13:04
  • As the other thread mentions the default is BsicHttpBinding with 1.1, so you need to put a configuration at both end, and ensure that the bindings are the same, or else this kind of error will pop up. – NatarajC Apr 12 '16 at 13:05
  • OK, trying to get access to the clients config, but it's maintained by a third party and the client is having trouble getting it. In the meantime I added and endpoint to my web.config and it's still coming up as SOAP12 in the WSDL. Config is -> – James Bender Apr 12 '16 at 13:09
  • Need to force the BasicHttpBinding to use SOAP1.1 by declaring a custom binding, then test it, and see that the SOAP envelope generated is same as what is being sent from client. – NatarajC Apr 12 '16 at 13:42
  • I added a custom binding and set the version to SOAP11, but the WSDL is still showing SOAP12: ----(config) – James Bender Apr 12 '16 at 18:45
  • In the WSDL I am seeing - – James Bender Apr 12 '16 at 18:48
  • Hi sorry for late reply, you can find some examples of configuration using basichttpbinding using soap11 in Google. Make sure to look at https://msdn.microsoft.com/en-us/library/ms731361(v=vs.110).aspx. Also note the .net version you are using since config differs in .net 4.0. And lastly don't forget to modify your endpoint definition in the config to use your new binding configuration, other wise the effect will not take place. All the best. – NatarajC Apr 13 '16 at 23:54
0

So, it turns out whoever wrote the initial version of the service didn't name the interface that they based their service contract on using an "I" as the first character. Even though a specific Action had been specified in the configuration, this was causing the message format mis-match.

James Bender
  • 1,175
  • 1
  • 11
  • 22