Issue when manually create the proxy classes

I have recently encountered this issue. In one of my project, I created the proxy class manually (sometimes I avoid using the Add Service Reference tool in visual studio and would happily create my own). While I am creating the proxy class, I have accidently did a spelling mistake in one of my method parameter name. I haven’t noticed it all. This caused the value sent to the WCF service is always null. The following code caused me the issue.

Service code


    [ServiceContract]
    public interface IBusinessManager
    {
        [OperationContract]
        string GetCompanyURL(string companyName);
    }

    public class BusinessManager : IBusinessManager
    {
        public string GetCompanyURL(string companyName) { ... }
    }

    [System.ServiceModel.ServiceContractAttribute(ConfigurationName = "BusinessManager.IBusinessManager")]
    public interface IBusinessManager
    {
        [System.ServiceModel.OperationContractAttribute(IsOneWay = true, Action = "http://tempuri.org/IBusinessManager/GetCompanyURL")]
        string GetCompanyURL(string CompanyName);
    }

    public partial class BusinessManagerClient : System.ServiceModel.ClientBase<businessmanager.IBusinessManager>,  BusinessManager.IBusinessManager
    {
        public string GetCompanyURL(string CompanyName)
        {
            return base.Channel.GetCompanyURL(CompanyName);
        }
    }

You might notice that the proxy method’s parameter name is CompanyName, and the service interface parameter name is companyName.

It is case sensitive and it wont give you any compilation error or runtime error, but you will see you application is not running as expected.

Verify the parameter name and make sure that the cases are also correct when you create your proxies.

No comments:

Post a Comment