WCF/WF - Webservice method invoke via SOAPHttpClientProtocol : Serialization of Array Objects Issue

Asked By Prakash C on 22-Apr-14 01:46 AM

Server Side :

Method 1:

[OperationContract(Action = "urn:getEmployee", Name = "getEmployee")]

[return: MessageParameter(Name = "getEmployeeReturn")]

Employee getEmployee(User user); // This works properly

 

     

Method 2:

[OperationContract(Action = "urn:getEmployees", Name = "getEmployees")]

[return: MessageParameter(Name = "getEmployeeReturn")]  // Here is the issue - missing something ?

Employee[] getEmployees(User user);

 

Client Side: (proxy - we should not change this)

Method 1 Call:

[SoapDocumentMethod("urn:getEmployee", RequestNamespace = "http://employee.com", ResponseNamespace = "http://employee.com", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]     

[return: XmlElement("getEmployeeReturn", Form = XmlSchemaForm.Unqualified, IsNullable = true)]

public Employee getEmployee([XmlElement(Form = XmlSchemaForm.Unqualified, IsNullable = true)] User user)

    {

        object[] arr_ = base.Invoke("getEmployee", new object[]

        {

          user     

        });

 

        return (Employee)arr_[0]; // This works properly

 

      }

 

Method 2 Call:

[SoapDocumentMethod("urn:getEmployees", RequestNamespace = "http://employee.com", ResponseNamespace = "http://employee.com", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]

[return: XmlArrayItem("elements", Form = XmlSchemaForm.Unqualified), XmlArray("getEmployeeReturn", Form = XmlSchemaForm.Unqualified, IsNullable = true)]

public Employee[] getEmployees([XmlElement(Form = XmlSchemaForm.Unqualified, IsNullable = true)] User user)

      {

        object[] arr_ = base.Invoke("getEmployees", new object[]

        {

          user     

        });

 

        return (Employee[])arr_[0];

      }

Problem:

Method 1 returns single object to client successfully, but Method 2 which returns the string ‘Employee[0]’ not the total array collection.

I know am missing something on [return] attribute of server side code of Method 2. Please help me... where am wrong ?

Robbe Morris replied to Prakash C on 22-Apr-14 08:00 AM
Method 2's signature returns an array not just one record.

return (Employee[])arr_;
Prakash C replied to Robbe Morris on 22-Apr-14 10:17 AM
Thanks Robbe for your reply.. actually the object arr[0] has the collection of Employee[] thats why casted like that.. Also the Client side code is proxy class, it is generated using the wsdl of Java webservice. using the same proxy we created similar webservice in C# which I mentioned as Server Side code. 

Its a Simulation Logic, here single proxy class will be used to contact Java Webservice also C# WCF service, so we should not change the proxy class code..

same proxy class -> Java webservice working fine
same proxy class -> C# webservice only issue..

Method 2:

[OperationContract(Action = "urn:getEmployees", Name = "getEmployees")]

[return: MessageParameter(Name = "getEmployeeReturn")]  // Here is the issue - missing something ?

Employee[] getEmployees(User user); I tried many attributes like below but no luck,

[return: XmlArrayItem("elements", Form = XmlSchemaForm.Unqualified), XmlArray("getVerificationInfosForVerificationRequestsReturn", Form = XmlSchemaForm.Unqualified, IsNullable = true)]

we need specify the return object is an array in C# server side code, so that SOAP client should understand for serialization.. please give your thoughts on it..

Robbe Morris replied to Prakash C on 22-Apr-14 10:33 AM
This is not how to reference the entire array:

arr[0]

This references the first element in the array.