aspose file tools*
The moose likes BlackBerry and the fly likes calling web services in blackberry Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Mobile » BlackBerry
Reply locked New topic
Author

calling web services in blackberry

Naayl kazmi
Greenhorn

Joined: Mar 22, 2011
Posts: 1
Hi, I am using Blackberry plugin for Java-Eclipse to write blackberry code on Windows XP SP3

I am using ksoap2.jar in my application for webservice call.



My webservice having one method called "HelloServer".



This code will return "java.io.InterruptedIOException: Local connection timed out after ~ 120000" exception.



Following is the code


1.How can i solve this problem..



2. What are the ways i have to implement in my code.



Thanks




======================================================================================
My .NET Web Service Code
======================================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

namespace HelloWorldService
{
//[WebService(Namespace = "http://tempuri.org/")]
[WebService(Namespace = "http://localhost:2901/")]
//[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//[System.ComponentModel.ToolboxItem(false)]
public class Service : System.Web.Services.WebService
{

[WebMethod]

public String HelloServer(String msg)
{
return "From Server, Hello - " + msg;
}

[WebMethod]
public String fnAddNumbers(int a, int b)
{
return "From Server, Hello - " + (a + b);
}

[WebMethod]
public String ShowMessage()
{
return "Welcome to KSoap2 Library";
}
}
}
======================================================================================

======================================================================================
My BlackBerry Code
======================================================================================

package com.criagagreen.sample;

import java.util.Date;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransport;

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;

//import net.rim.device.api.system.*;

public class HelloWorld extends UiApplication {
public static void main(String[] args) {
HelloWorld theApp = new HelloWorld();
theApp.enterEventDispatcher();
}

public HelloWorld() {
pushScreen(new HelloWorldScreen());
//String serviceUrl = "http:// <SERVER>/HelloWorldService/Service.asmx";
String serviceUrl = "http://localhost:2901/Service.asmx";
String serviceNamespace = "http://tempuri.org/";
String soapAction = "http://localhost:2901/HelloServer";

SoapObject rpc = new SoapObject(serviceNamespace, "HelloServer");

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);

envelope.bodyOut = rpc;

envelope.dotNet = true;
envelope.encodingStyle = SoapSerializationEnvelope.XSD;
rpc.addProperty("msg", (new Date()).toString());

HttpTransport ht = new HttpTransport(serviceUrl);
ht.debug = true;
String result;

try {
ht.call(soapAction, envelope);
result = (envelope.getResponse()).toString();
} catch (Exception ex) {
result = ex.toString();
}
((HelloWorldScreen) this.getActiveScreen()).setScreenTest(result);
}
}

final class HelloWorldScreen extends MainScreen

{
private RichTextField textField;

public HelloWorldScreen() {
super();
LabelField title = new LabelField("HelloWorld Web Service Sample",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
setTitle(title);
textField = new RichTextField("Hello World! from Web Service");
add(textField);
}

public void setScreenTest(String text) {
textField.setText(text);
}

public boolean onClose() {
Dialog.alert("Goodbye! from Web Service");
System.exit(0);
return true;
}
}

======================================================================================

islam farid
Greenhorn

Joined: Jul 18, 2011
Posts: 1
you should launck MDS in order to connect your web service you have two choices
1-download it from the internet
2-mark the checkbox in the run configurations then simulators
nishan satharasinghe
Greenhorn

Joined: Aug 27, 2008
Posts: 14
Hi Naayl,

Is islam has answered your question??


Please post if it is , otherwise we can have a look on to it.

Cheers
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: calling web services in blackberry