This week's book giveaway is in the Java in General forum.
We're giving away four copies of Java by Comparison (eBook) and have Simon Harrer, Jörg Lenhard, Linus Dietz on-line!
See this thread for details.
Win a copy of Java by Comparison (eBook) this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

calling .Net web Service by J2ME  RSS feed

Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've problem configuring the correct HttpTransport to call my .net Web Service. Could anyone help me ?? Please?
I think there is a mistake in in my new HttpProtocol("","") constructor invocation.
Thanx, Thanx in advance!!

this is my web service:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

namespace WS
/// <summary>
/// Descrizione di riepilogo per Service1.
/// </summary>
public class Service1 : System.Web.Services.WebService
public Service1()
//CODEGEN: chiamata richiesta da Progettazione servizi Web ASP.NET.
#region Component Designer generated code

//Richiesto da Progettazione servizi Web
private IContainer components = null;

/// <summary>
/// Metodo necessario per il supporto della finestra di progettazione. Non modificare
/// il contenuto del metodo con l'editor di codice.
/// </summary>
private void InitializeComponent()
/// <summary>
/// Pulire le risorse in uso.
/// </summary>
protected override void Dispose( bool disposing )
if(disposing && components != null)

// Il servizio di esempio HelloWorld() restituisce la stringa Hello World.
// Per generare, rimuovere i commenti dalle righe seguenti, quindi salvare e generare il progetto.
// Per verificare il servizio Web, premere F5.
public string sayHello()
return "Hello World";
and this is my simplest J2me code:

import java.lang.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import org.ksoap.*;
import org.ksoap.transport.*;
public class mio extends MIDlet implements
CommandListener, Runnable {
Form mainForm = new Form ("StockQuotes");
TextField symbolField = new TextField ("Symbol", "", 5,
StringItem resultItem = new StringItem ("", "");
Command getCommand = new Command ("Get", Command.SCREEN, 1);
public mio () {
mainForm.append (symbolField);
mainForm.append (resultItem);
mainForm.addCommand (getCommand);
mainForm.setCommandListener (this);
public void startApp () {
Display.getDisplay (this).setCurrent (mainForm);
public void pauseApp () {
public void destroyApp (boolean unconditional) {
public void commandAction (Command c, Displayable d) {

Thread th= new Thread(this);
public void run(){

try {
// Build request string
String symbol = symbolField.getString ();
resultItem.setLabel (symbol);
// Create a SoapObject by specifying the URN and themethod name
// of the SOAP RPC Web Service.
SoapObject rpc = new SoapObject
("http://localhost/WS/Service1.asmx", "sayHello");
// The addProperty method allows you to specify parametersto for
// the method used.
// rpc.addProperty ("symbol", symbol);
// The HttpTransport class can be used to make the actualcall.
// Its constructor accepts the Web Service endpoint as well as
// the method to be called.

resultItem.setText (""+new HttpTransport
"urn:Hello#sayHello").call (rpc));
catch (Exception e) {
e.printStackTrace ();
resultItem.setLabel ("Error:");
resultItem.setText (e.toString ());


public static void main (String [] argv) {
new mio ().startApp ();
and this is the soap request that my web service ask:
POST /WS/Service1.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "urn:Hello/sayHello"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="" xmlns:xsd="" xmlns:soap="">
<sayHello xmlns="urn:Hello" />
Ranch Hand
Posts: 1427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I recall kSOAP v1.0 requires the SOAP server to explicitly encode the type. For example, you need:

But .NET servers often givens literal SOAP messages with "default" types like this one:

I believe kSOAP v2 has a "dotnet" tag in its deserialize class and it is supposed to fix that problem.
Wink, wink, nudge, nudge, say no more, it's a tiny ad:
Thread Boost - a very different sort of advertising
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!