Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dears,

I am trying to use message contracts in WCF and i have a parent object with two sub objects in some method and after consuming the service from a test client, the method accepts only the sub objects as input and ignores the parent object!

Example:
WCF Method:
C#
public GetEmployeeResponse GetEmployee_MessageContract(GetEmployeeRequest getEmployeeRequest)
{            
    //Some code and return getEmployeeResponse;
}

GetEmployeeRequest:
C#
[MessageContract(IsWrapped =true, WrapperName = "GetEmployeeRequestObjectWrapped", WrapperNamespace ="http://www.test.com")]
    public class GetEmployeeRequest
    {
        [MessageHeader(Namespace = "http://www.test.com", Name = "AuthenticationHeaderObject")]
        public AuthenticationHeader AuthenticationHeader { get; set; }


        [MessageBodyMember(Namespace = "http://www.test.com", Name = "EMPID")]
        public int Id { get; set; }
    }

AuthenticationHeader:
C#
[DataContract]
    public class AuthenticationHeader
    {
        [DataMember(Name = "KEY", Order =1)]
        public string UserName { get; set; }

        [DataMember(Name = "PASSWORD", Order = 2)]
        public string Password { get; set; }
    }


The MAIN issue now is that while consuming this method from a client app i am getting the following in the service reference.cs file:
Method header is as following:
C#
GetEmployee_MessageContract(EmployeeService_Client.EmployeeService.AuthenticationHeader AuthenticationHeaderObject, int EMPID)


I expect it to be like
C#
GetEmployee_MessageContract(EmployeeService_Client.EmployeeService.GetEmployeeRequest GetEmployeeRequest)


So what is the problem with the above code?

What I have tried:

i tried using serializable in stead of DataContract but still the issue there?
Posted
Updated 6-Feb-19 21:49pm
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900