Meaningless Drivel is fun!*
The moose likes Web Services and the fly likes Ksoap / j2me / .Net Web Service Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Ksoap / j2me / .Net Web Service" Watch "Ksoap / j2me / .Net Web Service" New topic
Author

Ksoap / j2me / .Net Web Service

soren eriksen
Greenhorn

Joined: Nov 22, 2004
Posts: 4
Hi people

I am trying to connect to web service created in vb.net, through a midlet with KSoap.

My problem is not really connecting and getting a result, but rather setting a property in my midlet..

let me show you my code>

testWebService.java

------------------------------------------------------------------------
package testWebService;

/*
* testWebService.java
*
* Created on 21. november 2004, 19:18
*/

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;
import javax.microedition.io.*;

import org.ksoap.*;
import org.ksoap.transport.*;
import org.ksoap.SoapObject;

public class testWebService extends MIDlet {

private Display display;
private String url = "http://myDomain.dk/ws/ws.asmx";
TextBox textBox = null;
private Command cmExit;

public testWebService()
{
display = Display.getDisplay(this);

}

public void startApp() {
try
{
doWebService(url);
}
catch(Exception e)
{
System.out.println("Exception: " + e);
}

}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
destroyApp(false);
notifyDestroyed();
}


public void doWebService(String url) throws Exception
{
StringBuffer sb = new StringBuffer();
String name = "Phobos";
TextBox textBox = null;
SoapObject client = new SoapObject(url, "sayHello");
client.addProperty("name", name);



HttpTransport ht = new HttpTransport(url, "http://MyDomain.dk/ws/sayHello");
sb.append("" + ht.call(client));
System.out.println(client.getNamespace());

textBox = new TextBox("Simple Web Service Test: ", sb.toString(), 1024, 0);
display.setCurrent(textBox);
}

}

-------------------------------------------------------------------------

And the web service ws.asmx>

<%@ WebService language="VB" class="ws" %>

Imports System
Imports System.Web.Services
Imports System.Xml.Serialization

<WebService(Namespace:="http://myDomain.dk/ws/")> Public Class ws

<WebMethod> Public Function sayHello(name As String) As String
Return "hello mr. " & name
End Function
End Class

------------------------------------------------------------------------

When invoking the web service from the midlet I would prefer the result:

"hello mr. Phobos"

But the result is:

"hello mr."

No Phobos!

So my guess is that the addPropery() is not working somehow, most likely a mistake on my behalf, and this is where you, the people, enters the picture.. hopefully you can help me out..

By the way, I have tried to change the name of the property to something else (in midlet code) but this gave no error or nothing.

Thanks in advance!

/soren
[ November 24, 2004: Message edited by: soren eriksen ]
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Have tried using tcp/ip trace to see what http message is being transfered betwn mobile and server? escp the value "phobes" ??


Spritle Software Blogs
soren eriksen
Greenhorn

Joined: Nov 22, 2004
Posts: 4
Hi Balanji

Thats a really nice program, ive been looking for something like that for some time now, but never got around to doing something serious about getting one. But I would recommend YATT instead, since the other ones didnt seem to be working proper on my machine setup.

The response I get is this:

-------------------------------------------------------------------------

HTTP/1.1 100 Continue
Server: Microsoft-IIS/5.0
Date: Tue, 23 Nov 2004 20:43:21 GMT
X-Powered-By: ASP.NET
MicrosoftOfficeWebServer: 5.0_Pub

HTTP/1.1 200 OK
Server: Microsoft-IIS/5.0
Date: Tue, 23 Nov 2004 20:43:22 GMT
X-Powered-By: ASP.NET
MicrosoftOfficeWebServer: 5.0_Pub
X-AspNet-Version: 1.1.4322
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Content-Length: 361

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><sayHelloResponse xmlns="http://myDomain.dk/ws/"><sayHelloResult>hello mr. </sayHelloResult></sayHelloResponse></soap:Body></soap:Envelope>

--------------------------------------------------------------------------

This is only whats returned, and not what is sent though(?)

So it seems that somehow my parameters are either not sent or not set.

I did some googling this morning and found a site mentioning something about "soaprpcmethod"

(http://article.gmane.org/gmane.comp.java.enhydra.ksoap/375)

-------------------------------------------------------------------------
> First off, if you are using c#, *I* have found your webservice will play
> *much* nicer if you add this above your method declaration:
>
> [WebMethod]
> [System.Web.Services.Protocols.SoapRpcMethod]
> public *return type* *function name* (*param list*)
>
-------------------------------------------------------------------------

Ill try this out later, but if you have any experience with this, please me know:-)

/Soren
soren eriksen
Greenhorn

Joined: Nov 22, 2004
Posts: 4
Ok, found a solution... I am posting it because it may be to some help for someone else someday...

Code for midlet> (remember adding KSoap to the project)

---------------------------------------------------------------------------

package testWebService;
/*
* testWebService.java
*
* Created on 21. november 2004, 19:18
*/

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;
import javax.microedition.io.*;

import org.ksoap.*;
import org.ksoap.transport.*;
import org.ksoap.SoapObject;

public class testWebService extends MIDlet {

private Display display;
private String url = "http://myDomain.dk/ws/ws.asmx";
TextBox textBox = null;
private Command cmExit;

public testWebService()
{
display = Display.getDisplay(this);

}

public void startApp() {
try
{
doWebService(url);
}
catch(Exception e)
{
System.out.println("Exception: " + e);
}

}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
destroyApp(false);
notifyDestroyed();
}


public void doWebService(String url) throws Exception
{
StringBuffer sb = new StringBuffer();
String name = "Phobos";
TextBox textBox = null;
SoapObject client = new SoapObject("http://myDomain.dk/ws/", "sayHello");
client.addProperty("name", name);



HttpTransport ht = new HttpTransport(url, "sayHello");
sb.append("" + ht.call(client));
System.out.println(client.getNamespace());


textBox = new TextBox("Simple Web Service Test: ", sb.toString(), 1024, 0);
display.setCurrent(textBox);
}

}

--------------------------------------------------------------------------

Code for webservice>

--------------------------------------------------------------------------

<%@ WebService language="c#" class="ws" %>

using System;
using System.Web.Services;
using System.Xml.Serialization;
using System.Web.Services.Protocols;



[WebService(Namespace="http://myDomain.dk/ws/")]
[SoapDocumentService(RoutingStyle=SoapServiceRoutingStyle.RequestElement)]
public class ws{

[WebMethod]
[System.Web.Services.Protocols.SoapRpcMethod]

public string sayHello(string name)
{
return "hello mr. "+name;
}
}

---------------------------------------------------------------------------

By the way is it possible to change the name of this thread, maybe it could be more useful if it had a more saying title?

/Soren
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Originally posted by soren eriksen:
By the way is it possible to change the name of this thread, maybe it could be more useful if it had a more saying title?
/Soren


Soren you can change the subject by clicking the icon , in your first post of this thread.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ksoap / j2me / .Net Web Service
 
Similar Threads
Consuming "Hello"web service from mobile
Problem in connecting web service from j2me
Where do the CLDC class files need to be placed?
the trouble of openInputStream()!
calling .Net web Service by J2ME