Marco Battaglia

Greenhorn
+ Follow
since Feb 17, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Marco Battaglia

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>
[WebService(Namespace="urn:Hello")]
public class Service1 : System.Web.Services.WebService
{
public Service1()
{
//CODEGEN: chiamata richiesta da Progettazione servizi Web ASP.NET.
InitializeComponent();
}
#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)
{
components.Dispose();
}
base.Dispose(disposing);
}

#endregion
// ESEMPIO DI SERVIZIO WEB
// 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.
[WebMethod]
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 java.io.*;
import javax.microedition.io.*;
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,
TextField.ANY);
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);
th.start();
}
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
("http://localhost/WS/Service1.asmx",
"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="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<sayHello xmlns="urn:Hello" />
</soap:Body>
</soap:Envelope>
20 years ago
I know that it's a beginner's answer, but I don't know how to import optional packages in my j2me projects.
For example mmapi
When I use J2MEWToolKit everythings is made automatically, but if I use JBuilder there are no classes for mmapi or xml.
Have I to use a particular reference during my compilation? How
Thanx in advance
20 years ago
Thanx Yuan, I'm reading your book, bought in Italy.
20 years ago
In my code, sending a request to an http server, I've to add some params/values via GET method, but I noticed that all will works only by formating my http request (for example replacing 'space' with '%20'). My question: Exists an UrlEncoding method? Have I to define any HttpConnection's property.
Thanx in advance.
Marco
HttpConnection http = null;
InputStream iStr = null;
String str = null;
boolean ret = false;
if (c == cmdExit) {
destroyApp(false);
notifyDestroyed();
}
if (c == cmdTest) {
if (txt.getString() != null)
System.out.print(txt.getString());
try {
String formatQuery= txt.getString();
http = (HttpConnection) Connector.open(
"http://XXXXXXX/J2meServer/nonQuery.aspx?sql=" +
formatQuery(txt.getString()));
iStr = http.openInputStream();
String msg=new String("");
msg=processServerResponse(http, iStr);
private String formatQuery (String oldQuery)
{
String newQuery=new String(oldQuery.trim());
while (newQuery.indexOf(' ')!=-1)
{
int i=newQuery.indexOf(' ');
System.out.print("\n"+newQuery);
newQuery=newQuery.substring(0,i)+"%20"+newQuery.substring(i+1, newQuery.length());
}
return newQuery;
}
20 years ago