jQuery in Action, 2nd edition*
The moose likes Web Services and the fly likes Need some advice on returning record sets from a web service to a C# client. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Need some advice on returning record sets from a web service to a C# client." Watch "Need some advice on returning record sets from a web service to a C# client." New topic
Author

Need some advice on returning record sets from a web service to a C# client.

Steve Vittoria
Ranch Hand

Joined: Jan 12, 2005
Posts: 33

Hi everyone,

I'm quite new to write web services and I've been tasked with writing a web service that gets data from an Oracle DB using Hibernate. I need to return those results and my client app is a C# desktop application.

Here is what my web service looks like...


This is the method that the C# client calls...


When my C# client calls getAllTemplates which returns a String, it works fine. However my C# client can't seem to be able to call the getListAllTemplates, and I suspect that is due to the fact that getListAllTemplates retunrs a List. I don't get any errors (or at least none that I can see in Visual Studio), but this is what I see in Visual Studio when I provide the WSDl for my web service...



The method that returns a List does not have a "Response" in Visual Studio.

My question is, is returning a List the best way to go about this? Should I return something else, perhaps XML? The other thing to keep in mind is in addition to returning results from an Oracle DB, my web service also needs to be able to return a BLOB, a Word document (which is basically a binary if I'm not mistaken). So I'm kind of at a lost as to how best to proceed to return the data.

Thanks!
Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 576

Hi Steve,
The method that returns a List does not have a "Response" in Visual Studio.

I presume you are using bottom-up(Java to WSDL) approach in creating your WSDL file. I suspect if your WSDL has been updated after including getListOfAllTemplates() method. Have you double checked this?

is returning a List the best way to go about this?

It is perfectly fine to return List. The corresponding WSDL mapping contains element with maxOccurs="unbounded".

a Word document (which is basically a binary if I'm not mistaken). So I'm kind of at a lost as to how best to proceed to return the data.

There are couple of options.
1. Using SOAP "inline" attachments.
xsd:base64Binary or xsd:hexBinary types in WSDL allow to represent your attachments for small sized files.
(by mapping Base64/Hex encoded resource stream to the above types)

You can use MTOM to optimize your SOAP messages if you feel file content is relatively large. Check out this link.

2. Using SwA
Check out this post.


Cheers,
Naren
(OCEEJBD6, SCWCD5, SCDJWS, SCJP1.4 and Oracle SQL 1Z0-051)
Steve Vittoria
Ranch Hand

Joined: Jan 12, 2005
Posts: 33

Hi Naren! Thanks for the reply.

First off, I neglected to mention that I'm hosting my web service on JBoss 4.3.0GA. I'm not sure if that makes a huge difference.

Naren Chivukula wrote:
I presume you are using bottom-up(Java to WSDL) approach in creating your WSDL file. I suspect if your WSDL has been updated after including getListOfAllTemplates() method. Have you double checked this?


To be honest with you I'm not sure which appoarch I'm using to create the WSDL file. I'm developing my web service using JBoss Developer Studio and host my web service on JBoss 4.3.0GA. The getListOfAllTemplates() method is in the WSDL file that I provide to Visual Studio.

Here is my WSDL file...


Naren Chivukula wrote:
It is perfectly fine to return List. The corresponding WSDL mapping contains element with maxOccurs="unbounded".


Is it fine knowing that the client is a C# program? I'm still wondering if C# can call a web service that returns a List.

As for returning a Word document, I'll have a look into the 2 options you provided. Hopefully one of the options will work with a C# client.
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Just want to add one thing to the previous, excellent, answers:
Using Java collection types, such as List, Map etc in return types in methods that are exposed as web service operations is not a good idea since JAXB does not know how to handle these well.
Using an array is much better.
In your case, returning OwordTest[] is the preferred way.
Best wishes!


My free books and tutorials: http://www.slideshare.net/krizsan
Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 576

Agree with Ivan. However, List and generic Collection should work without any problem in JAX-WS. Because, I'm working on some web service operations which have these return types. But, I appreciate the idea of using arrays instead of Collection as I saw nightmares long time ago when working with Websphere WSIF framework.

The getListOfAllTemplates() method is in the WSDL file that I provide to Visual Studio.

It seems that after adding this method in WSDL, client side artefacts might not have been created?! As I see your WSDL, element "GetListOfAllTemplatesResponse" is properly mapped to List. Even if you had array instead of List, the element definition should appear same!

Is it fine knowing that the client is a C# program? I'm still wondering if C# can call a web service that returns a List

I don't think why it shouldn't work in your case.

As for returning a Word document, I'll have a look into the 2 options you provided. Hopefully one of the options will work with a C# client.

I suggest you first try with "inline" attachments (preferably using MTOM).
Steve Vittoria
Ranch Hand

Joined: Jan 12, 2005
Posts: 33

Naren Chivukula wrote:
It seems that after adding this method in WSDL, client side artefacts might not have been created?! As I see your WSDL, element "GetListOfAllTemplatesResponse" is properly mapped to List. Even if you had array instead of List, the element definition should appear same!


Yes I believe you are correct. I just added a new method to my web service, which simply returns an array of String. Very simple one dimensional array, and when I generate a new WSDL and import it in Visual Studio, I have the same results as with my method that returns a List. Now I`m even more lost and confused than ever. C# should be able to handle a web service method that returns an array!?!? As unlikly as this might sound... is it possible that somehow the WSDL file being generated by JBoss be incorrect? Can this be some JBoss issue?

Is it possible to convert a List to XML? Would that not be a better way for a web service to return data?
Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 576

Hi Steve,
is it possible that somehow the WSDL file being generated by JBoss be incorrect?

I haven't quite understood what incorrect part of WSDL you are referring here!

Is it possible to convert a List to XML? Would that not be a better way for a web service to return data?

If you are concerned of how to handle method returning List in C# client, then you may have to check first what data type (List or array) your generated C# client artefacts contain because it depends on Web Services API to decide what data type has to be created though in most of the cases, array.

If you are asking your question above in Java world, there is an API XStream, which is used to convert java objects to xml and vice-versa. In this way you can always pass/return String. Having said that, if you can parse xml string in C# with your custom code, you can still use XStream on server side.
Steve Vittoria
Ranch Hand

Joined: Jan 12, 2005
Posts: 33

Naren Chivukula wrote:Hi Steve,
is it possible that somehow the WSDL file being generated by JBoss be incorrect?

I haven't quite understood what incorrect part of WSDL you are referring here!


I was just wondering if there was something unique about a JBoss generated WSDL file that C# doesn't like. I still find it very odd that I can't even call a method that returns an array.
Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 576

I think generated WSDL should be same had we generated using some other Web Services API. Also, generated WSDLs would be compliant to WSDL2.0 schema(given that you are working on JAX-WS). However, you can validate generated WSDLs if you manually make any changes or just to double check using any IDE which supports web services (option is mostly provided upon right-clicking on the WSDL).
I still find it very odd that I can't even call a method that returns an array.

This would be bizarre to me as arrays are supported in almost in all languages!
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Can a C# program correctly read and process a Java List object?



Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Have you seen the WSIT - web service interoperability technologies?
If not, I recommend taking a look at: http://download.oracle.com/docs/cd/E17802_01/webservices/webservices/reference/tutorials/wsit/doc/WSITTutorial.pdf
When interacting between Java and C#, there are quite some guidelines that should be observed.
Also, it is quite important that you use the appropriate version of the language frameworks - I think there are more about this in the WSIT tutorial.
I've had problems in the past simply because of the version of the .NET framework I used. Switching version solved the problems.
Best wishes!
Steve Vittoria
Ranch Hand

Joined: Jan 12, 2005
Posts: 33

Naren Chivukula wrote:
I still find it very odd that I can't even call a method that returns an array.

This would be bizarre to me as arrays are supported in almost in all languages!


I agree, which leads me to believe that I must be doing something wrong and/or missing something. In any case, I have managed to return the data by converting my List to xml using XStream (thanks for the tip Naren! ), and was easily able to work with the xml in my C# client application.

Now my big challenge is to return a BLOB (a Word document) to the client, and the client will be returning me that blob (of course after the user has made some changes to the document). So I need to find a way to pass a Word document to the client and back to the web service. Something tells me this won't be very straight forward.

Ivan Krizsan wrote:
Have you seen the WSIT - web service interoperability technologies?
If not, I recommend taking a look at: http://download.oracle.com/docs/cd/E17802_01/webse...ials/wsit/doc/WSITTutorial.pdf


Thanks for the link Ivan. I haven't heard of WSIT, but I'll have a look.
Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 576

Hi Steve,
Glad you got through one hurdle!

So I need to find a way to pass a Word document to the client and back to the web service. Something tells me this won't be very straight forward.

Not sure how you would do in C# this function but on Java side you can have a look at the couple of options I mentioned. It should be quite straight forward atleast on Java side.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need some advice on returning record sets from a web service to a C# client.
 
Similar Threads
How can I secure a web service?
Why is my WS expecting a XMLGregorianCalendar datatype?
Getting an error while returning a blob using Hibernate
Why is Hibernate updating after a select?
How to join two tables on columns that have different names?