WCF Service and JAVA client
-
Hi, I am having a WCF service which exposes two functions. One returns a string and another returns an array of custom object Employee. Employee class is a DataContract and all it contains is simple premitive data types marked as DataMember. First method works fine but I am not able to get the second method GetEmployeeArray() working. Any clues how to pass complex data types with premitive data members in WCF? :^)
Jayant D. Kulkarni Brainbench Certified Software Engineer in C#, ASP.NET, .NET Framework and ADO.NET
-
Hi, I am having a WCF service which exposes two functions. One returns a string and another returns an array of custom object Employee. Employee class is a DataContract and all it contains is simple premitive data types marked as DataMember. First method works fine but I am not able to get the second method GetEmployeeArray() working. Any clues how to pass complex data types with premitive data members in WCF? :^)
Jayant D. Kulkarni Brainbench Certified Software Engineer in C#, ASP.NET, .NET Framework and ADO.NET
Just curious but what type of formatter are you using. I have had success using the BinaryFormatter but it has a bit different syntax from the Messaging namespace for MSMQ. I was passing a generic list and it was working pretty good. Can you post a code bit of code so I can see what it looks like?
-
Just curious but what type of formatter are you using. I have had success using the BinaryFormatter but it has a bit different syntax from the Messaging namespace for MSMQ. I was passing a generic list and it was working pretty good. Can you post a code bit of code so I can see what it looks like?
Thanks for the quick reply Kevin. Here is my code. My Service Contract looks like this.
using System; using System.Collections.Generic; using System.Text; using System.ServiceModel; using System.Data; namespace WCFService { [ServiceContract] public interface IWCFService { [OperationContract] string GetSystemIPAddress(); [OperationContract] object[] GetEmpolyeeArray(); } }
The class implementing the service contract looks like this.using System; using System.Collections.Generic; using System.Text; using SystemInfo; using System.Data; using System.ServiceModel; namespace WCFService { [ServiceBehavior(IncludeExceptionDetailInFaults = true)] public class WCFService : IWCFService { #region IWCFService Members public string GetSystemIPAddress() { return new SystemInfo.SystemInfo().GetIPAddress(); } public object[] GetEmpolyeeArray() { DataSet ds = new SystemInfo.SystemInfo().GetEmployeeList(); Employee[] emps = new Employee[ds.Tables[0].Rows.Count]; int index = 0; foreach (DataRow row in ds.Tables[0].Rows) { emps[index] = new Employee(); emps[index].EmployeeID = Convert.ToInt32(row["EmployeeNo"]); emps[index].Experience = Convert.ToDecimal(row["Experience"]); emps[index].FirstName = row["FirstName"].ToString(); emps[index].LastName = row["LastName"].ToString(); emps[index].MiddleName = row["MiddleName"].ToString(); emps[index].Qualification = row["Qualification"].ToString(); index++; } return emps; } #endregion } }
My DataContract is thisusing System; using System.Collections.Generic; using System.Text; using System.ServiceModel; using System.Runtime.Serialization; namespace WCFService { [DataContract] public class Employee { [DataMember] public int EmployeeID; [DataMember] public string FirstName; [DataMember] public string MiddleName; [DataMember] public string LastName; [DataMember] public decimal Experience; [DataMember] public string Qualification; } }
My Java client is like t -
Thanks for the quick reply Kevin. Here is my code. My Service Contract looks like this.
using System; using System.Collections.Generic; using System.Text; using System.ServiceModel; using System.Data; namespace WCFService { [ServiceContract] public interface IWCFService { [OperationContract] string GetSystemIPAddress(); [OperationContract] object[] GetEmpolyeeArray(); } }
The class implementing the service contract looks like this.using System; using System.Collections.Generic; using System.Text; using SystemInfo; using System.Data; using System.ServiceModel; namespace WCFService { [ServiceBehavior(IncludeExceptionDetailInFaults = true)] public class WCFService : IWCFService { #region IWCFService Members public string GetSystemIPAddress() { return new SystemInfo.SystemInfo().GetIPAddress(); } public object[] GetEmpolyeeArray() { DataSet ds = new SystemInfo.SystemInfo().GetEmployeeList(); Employee[] emps = new Employee[ds.Tables[0].Rows.Count]; int index = 0; foreach (DataRow row in ds.Tables[0].Rows) { emps[index] = new Employee(); emps[index].EmployeeID = Convert.ToInt32(row["EmployeeNo"]); emps[index].Experience = Convert.ToDecimal(row["Experience"]); emps[index].FirstName = row["FirstName"].ToString(); emps[index].LastName = row["LastName"].ToString(); emps[index].MiddleName = row["MiddleName"].ToString(); emps[index].Qualification = row["Qualification"].ToString(); index++; } return emps; } #endregion } }
My DataContract is thisusing System; using System.Collections.Generic; using System.Text; using System.ServiceModel; using System.Runtime.Serialization; namespace WCFService { [DataContract] public class Employee { [DataMember] public int EmployeeID; [DataMember] public string FirstName; [DataMember] public string MiddleName; [DataMember] public string LastName; [DataMember] public decimal Experience; [DataMember] public string Qualification; } }
My Java client is like tOk don't take this as fact I am working through the WCF myself. I had very similar issues so I experimented with the [XmlSerializerFormat] attribute for the service contract and got better results. I am not sure what the precise issue is but it seems to be related to the serilization of the array. I used a generic list instead of an array but I cannot see that that would make any difference.
-
Ok don't take this as fact I am working through the WCF myself. I had very similar issues so I experimented with the [XmlSerializerFormat] attribute for the service contract and got better results. I am not sure what the precise issue is but it seems to be related to the serilization of the array. I used a generic list instead of an array but I cannot see that that would make any difference.
Hi Kevin, Thanks again and I am trying with [XmlSerializerFormat] attribute. But I do not know it is showing some wierd error like this.
Web service client can not be created by JAXWS:wsimport utility.
Reason: duplicate "message" entity: "IWCFService_GetSystemIPAddress_InputMessage"My WSDL is like this.
- - - - - - - -
-
Ok don't take this as fact I am working through the WCF myself. I had very similar issues so I experimented with the [XmlSerializerFormat] attribute for the service contract and got better results. I am not sure what the precise issue is but it seems to be related to the serilization of the array. I used a generic list instead of an array but I cannot see that that would make any difference.
Hi Kevin, Finally I have done with it. The problem is not with WCF and [XmlSerializerFormat] attribute is also not required for service contract. The key concept is JAVA client can not get an Array of object of DataContract member. I have tried several ways but Array of Employee class never worked out. I tried it with List and it worked very fine. Thanks for your prompt response and guidance.:-D
Jayant D. Kulkarni Brainbench Certified Software Engineer in C#, ASP.NET, .NET Framework and ADO.NET