Question

I have a WCF service hosted on 2 servers. There was a function called GetData(param1). I changed this function to accept 2 parameters i.e. GetData(param1,param2). I updated the service on server1 and I updated the client code.

A weird thing is happening. the updated client code still works with the outdated service although the functions don't match. The function is being called and the results are returned. The added parameter is an enumeration value type if that helps. But why have such a non-deterministic behavior? and how does it work?

Was it helpful?

Solution

This thing is that when you design your method in a procedural way all you input parameters are optional by default and are populated with default values if you don't specify them explicitly. Assume you have a method with the following signature:

[OperationContract]
void TestMethod(string param1, int param2);

You will get the following WSDL for it:

<xs:element name="TestMethod">
     <xs:complexType>
       <xs:sequence>
        <xs:element minOccurs="0" name="param1" nillable="true" type="xs:string" />
        <xs:element minOccurs="0" name="param2" type="xs:int" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>

As you can see minOccurs attribute has 0 value which means the element is optional. So this is not surprising that your method works even after you added a new parameter.

If you want to avoid this behavior try to design your contracts in a message way by using MessageContract or at least wrapping all you parameters in a container class. And specify explicitly which parameter is required and if it allows default value via DataMember attribute.

Hope it helps!

OTHER TIPS

If your service has installed more than once place. Recheck your endpoint address to ensure its pointing right hosted server.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top