tags:

views:

983

answers:

3

I have a wcf serivce I want to consume from a j2me application (blackberry).

I have been going crazy since the tools that work fine for the j2SE used for consuming web services do not work all that well for j2me. At least not with my service.

I found a useful tutorial at http://www.netbeans.org/kb/60/mobility/mobile-dilbert.html

While it uses an old asmx service style to explain it. I was able to follow the steps and use my wcf reference and I was able to make the connection.

The drawback, this solution uses a j2ee proxy to get the reference to work.

Is this the way to solve the incompatibilities between .net and java? I read that a big reason why this happens is that Microsoft generates non-standard wsdl files for services.

My question is: is this the solution generally used for consuming .net web services from java, or is there a better way? Any reference pointers will be greatly appreciated.

A: 

Sebastian,

The only complaints I've heard about non-standard Microsoft WSDL have been complaints that the WSDL is not flat. That is, one WSDL may refer to another WSDL or to an XML schema defined in another file. Some platforms can't handle that. In particular, I recall that one such complaint was from someone doing smart device development. I don't recall if it was j2me.

There's not meant to be anything special to do. ASMX services are very basic old-style SOAP services; WCF additionally supports the WS-* standards. But they should all play nicely together.

Can you say exactly what problem you had when you were having trouble getting it to work with j2me? Please post all the exceptions, error messages, etc. Hopefully, any that need translation from Java into .NET, I'll be able to get some help with.

John Saunders
Using netbeans (create new web service client) I added the reference to the generated wsdl file for my wcf service.I got immediately the error (j2me)char, guid and duration where not supported. While my application do use guids, it does not use char(all text are strings), duration (read maps to timespan) I do not use. Just a basic example on one method, j2se was simple, I added the reference, draged the method i wanted to the source file(nice netbeans feauture) created a small stub, called the method got a good response. Guids translated to strings. (Continued)
Sebastian
on j2me, I could not even get the reference into the project. using eclipse I could not find any tools to get the web reference. I am spoiled by visual studio, so easy to click ass reference to a web service and call it). With some success i was able to use the method of a j2ee proxy, just would like to remove the proxy part.And thank you for your help :)
Sebastian
@Sebastian: The Netbeans/j2me issue seems to be about what j2me supports, right? And the second j2me seems to be no tools for it in Eclipse. Please tell me if I'm misunderstanding. I haven't used Eclipse in over a year, and then didn't really know what I was doing.
John Saunders
One of the methods is to retrieve a session token and throws an exception on bad user name or password. calling this method from java on bass data i get the exception as expected, when calling with good data i get an empty object back.
Sebastian
Yes my issue is with j2me. The application will run on a blackberry using j2me, and i cannot get the web reference into the project.(netbeans complains)(eclipse there seems to be no support for wsdl services)
Sebastian
Good. Just checking. I prefer it when it's the Java side of the world that's at fault. ;-) I've _so_ come to loath certain Apache SOAP versions.
John Saunders
Java SE can handle it. I found a nice mac os x client for testing services and it can handle it(written in objective-c) http://ditchnet.org/soapclient/. J2EE can handle it. Makes me mad j2me has trouble.I am going back to basics, go for the most basic service. And see.Temporary solution is the method of using a j2ee as proxy as explained in the link on my question.
Sebastian
A: 

Hi Sebastian,

Firstly, did you configure the WCF service to use basicHttpBinding?

Secondly, use only native data types (strings, int, bool, etc.) in the data contract. Don't use .NET objects like DateTime etc. This is what I did when I had to develop a MIDLet twitter app that calls a WCF service to get friend updates, post tweets etc... Oh and I also used Wireless Toolkit (v 2.5.2) stubgenerator to create the client. It didn't have any problem creating the client even if the WCF's wsdl had external imports (wsdl:import and xsd:import)

With the answers provided until this point I and my experiments. I did notice datetime had issues. Using the j2me sdk tools to generate stubs, I had mixed results. on the graphical ui no code was generated as it complains on java.util.calendar, on the command line tool it complained on the same, but files where generated. Errors on calendar, and errors on places where UNKOWN token was introduced. What is frustrating is that j2se had no problems calling the same reference.
Sebastian
Your observations are correct. Not everything you can do in J2SE is doable in J2ME primarily because of the limitations of the device its running on. If you're having issues with DateTime, why not just convert it into a string and parse it back into a date on the client side?
A: 

Thank you to the two people who answered, gave me things to think about when doing additional research.

Since there was no definite answer on this question, perhaps I was not clear, and after looking into the subject from other sources. I decided to post what I had discovered.

Looking at the most basic WCF service, one that has one method, returns a string. No other methods in place. Got the errors while adding the reference.

JSR-172 does not understand guids (the idea of the message not the actual message). Same thing for char and duration.

I read about it further and found references on microsoft non standard wsdl files, and that by implementing some interfaces you could remove all non standard schema references from the generated wsdl file.

This helped for a simple service not a complex one.

I tried an existing service, I decided to use the amazon.com affiliate services to test things.

Similar error as with my wcf service, it gave a whole list of types it did not like.

In the end I learned. Visual studio spoils you and makes you lazy(not always a bad thing). I wanted a way to use some sort of wizard type tool, input a reference and get lots of generated code that calls my service, gives my objects to deal with and methods to call.

Netbeans did this for me for J2SE not for j2me.

If you want to use WCF directly for a j2me project, be ready to write all the plumbing code for it.

Alternatively you can use the suggested method of using j2ee proxy. As explained in http://www.netbeans.org/kb/60/mobility/mobile-dilbert.html

With this method you still need to be careful what data types you use. As some cause the service to fail or be unusable. Example, i had a method return a datetime, netbeans would not even let me select that method for stub generation. and calling methods in the service with that one present caused exceptions to be thrown. (method removed and calls succeeded)

Sebastian
Sebastian, what guids are you referring to? What types caused problems. Could you post the errors? And what non-standard schema references?
John Saunders
Perhaps a better explanation of my problem. I found this method of solving things, after i wrote my question. My goal is to try to avoid changing the wcf side as much as possible. http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/df9fcce7-816c-4ed5-9bb4-c0c40f5f65e4
Sebastian