0

I have a C# webservice that a C#-client can access. I wish to create a java-client that can recieve data from the same Webservice. The Webservice has a data access layer that collects information from a foreign database. My problem is that the C#-webservice return type is not compatible with the java-client. Heres my example code:

    public DataTable EmployeeNames()
    {
        Connect();
        DataSet dataset = new DataSet();
        SqlDataAdapter adapter = new SqlDataAdapter();
        adapter.SelectCommand = new SqlCommand("SELECT [First Name], [Last Name] FROM [dbo].[CRONUS Sverige AB$Employee]", con);

        adapter.Fill(dataset);

        DataTable datatable = dataset.Tables[0];

        Close();
        return datatable;
    }

As you can see, this webmethod returns a DataTable, which as to my understanding, Java can not process. Same goes for DataSet. I've tried converting the data to a List/Array etc but then I get problems with the columns (what do I do with the column names for example?). I'm out of options here, any help is appreciated.

P.S. The C# client works perfectly.

1
  • You can make a class and return a list of objects of that class., Commented May 4, 2015 at 10:41

2 Answers 2

2

You said that you have tried to convert he data to a list or array, thus I assume that changing the method signature is something you can do.

What you could do, would be to instead return Collection of Employee objects. The Employee object would wrap around some of the data you have in the database, and within the EmployeeNames() method you perform the required translations.

This should make it easier for Java to read, since Java has a concept of a collection, or maybe an iterable.

As per your comment, you could try and convert the DataSet to a JSON Object, as shown here.

As an FYI, you do not need to expose all the fields, just the ones you want.

Sign up to request clarification or add additional context in comments.

4 Comments

I can not create a Employee-object because, and this is going to sound a little strange, I do not have access to all of the employee information (name, lastname etc). The code in my question is just an example. What I'm aiming for is a conversion of DataTable or DataSet to something that Java can process. Or something like that.
@Dinco: I've updated my answer, hopefully it will help.
I think this is out of my league. I'm still a novice programmer and this is above my knowledge. Is there not some other easier way, maybe not using DataSet or DataTable at alla and rather go for a DataReader instead?
@Dinco: The serialization will yield a JSON object, which is something for which Java parsers exist. In software development doing something which might seem to be beyond your current skills is something which is fairly common. The easier approach would be to ditch .NET custom objects and instead create your own.
0

You can call webservice from anywhere. Be it from C#, Java or anywhere else. The question is how you are exposing your web service. I recommend exposing it as a REST service, that way it will be accessible from everywhere. There is plenty of information available on the web on how to implement RESTful services. Once you implement the REST service, then you access it using HTTP GET, PUT, UPDATE, ETC... from your choice of environment.

1 Comment

As I mentioned above, this is out of my league. I'm still a novice programmer and this is way above my knowledge. I'm searching for a return-type like List or Array or something. Simple stuff.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.