views:

31

answers:

2

Hi,

I have WCF service. I have changed the name of the variable in datacontract, rebuilt service but did not rebuilt client

Before, this is operation contract for client

[OperationContract(Name = "SubscribeWcfProvider")]
bool Subscribe(Guid subscriptionid);

After, this is operation contract for service

[OperationContract(Name = "SubscribeWcfProvider")]
bool Subscribe(Guid subscriberId);

Now when client calls method the Guid is always null. It seems that I cannot change variable names? Why is that?

UPDATE

Please tell what happens behind the scene? How a function call is converted to message?

+1  A: 

It depends on your serialization choice. In general, if the name of the parameter appears in the serialized message, it's not going to translate properly if you change its name in the service and not the client - and that is almost always the case (SOAP, XML, JSON, etc.).

Eric Mickelsen
+4  A: 

The proxy you generated was (in all likelihood) created before the change and not regenerated after it. So the proxy "hardcoded" the parameters based on the WSDL (I'm assuming your using SOAP). Here is an example of a SOAP message (taken from this site).

<?xml version='1.0'?>
<SOAP:Envelope
  xmlns:SOAP='urn:schemas-xmlsoap-org:soap.v1'>
 <SOAP:Body>
  <i:getBalance
    xmlns:i='urn:develop-com:IBank'>
   <account>23619-22A</account>
  </i:getBalance>
 </SOAP:Body>
</SOAP:Envelope>

In this case the getBalance method expects the account parameter. If this changes on the server side and the client doesn't get the new contract and rebuilds the proxy, it will not be able to send in the correct parameter.

Note that if you need to make breaking changes like these in your code without breaking the contract, you can apply the MessageParameterAttribute on the parameter in the following way:

[OperationContract(Name = "SubscribeWcfProvider")]
bool Subscribe([MessageParameter(Name = "subscriptionid")]Guid subscriberId);

There is a good example on that on MSDN which shows the code you need to edit as well as the message that will be sent.

I recommend that you take a look at your service's generated WSDL in order to see in action what's happening behind the scenes.

steinar