How to use web service in J2ME application?

浪尽此生 提交于 2019-11-28 10:38:30

You can consume webservices in j2me, following would be the architecture look like,

If your phone does not support JSR172, or you want to target every phone in the market, you still can consume webservices manually. That is to say, you need to create an XML to invoke the service, and parse another one to see the results. This can be a lot of work. There is library called kXML2 that may help you in both task. But when I needed to invoke a webservice from j2me I found to be easier to follow this workflow:
1 - Use visual studio to create a simple client application for that webservice in .Net. So I can be sure the service works as expected without relaying in my j2me client, which is still in development. 2 - Use a tracer like http://simile.mit.edu/wiki/HTTPTracer to spy the connection and see what is really happening between client and server...it's kind of fun.
3 - Duplicate this behavior in my own j2me application ...but trying to keep it simple. As an example, I needed to create an XML like

<SOAP>  
   <data>  
        <id>  
           numericID  
        </id>  
   </data>  
</SOAP>  

Since I knew it was going to be a numeric Id, I just create the XML as a String using a stringbuffer.
4 - Be careful about the String encoding and the http headers. You can compare your generated traffic in j2me with the one the client. You need to replicate the exact behavior

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!