Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. WCF Service and JAVA client

WCF Service and JAVA client

Scheduled Pinned Locked Moved C#
csharpjavaasp-netdotnetwcf
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jdkulkarni
    wrote on last edited by
    #1

    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

    K 1 Reply Last reply
    0
    • J jdkulkarni

      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

      K Offline
      K Offline
      KevinMac
      wrote on last edited by
      #2

      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?

      J 1 Reply Last reply
      0
      • K KevinMac

        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?

        J Offline
        J Offline
        jdkulkarni
        wrote on last edited by
        #3

        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 this using 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

        K 1 Reply Last reply
        0
        • J jdkulkarni

          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 this using 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

          K Offline
          K Offline
          KevinMac
          wrote on last edited by
          #4

          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.

          J 2 Replies Last reply
          0
          • K KevinMac

            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.

            J Offline
            J Offline
            jdkulkarni
            wrote on last edited by
            #5

            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.
            - - - - - - - -

            1 Reply Last reply
            0
            • K KevinMac

              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.

              J Offline
              J Offline
              jdkulkarni
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups