View Single Post
Old 03-17-2010, 08:59 AM   #53
roshanthecho
New Member
 
Join Date: Mar 2010
Model: 8330
PIN: N/A
Carrier: sprint
Posts: 5
Default

I am trying to call my local web service (h**p://localhost:2715/Service1.asmx) created in .NET from BB application. I am using Eclipse 3.4.1 version. I have created library project and added the reference to the main project. While running in BB Simulator, it doesnot show any error message and also doesnot give the result of Web Method call.
While debugging, after displaying HelloWorld text and Service call button, it says "Source not found" with "Class File Editor" title and it also has a button "Change Attached Source...". What was the error? Please someone help me.

Here is my test code.

package com.fcs.sample;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope ;
import org.ksoap2.transport.HttpTransport;
import org.xmlpull.v1.XmlPullParserException;

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.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;

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

public MyWebServiceTest() {
pushScreen(new HelloWorldScreen());
}
}

final class HelloWorldScreen extends MainScreen {
private RichTextField textField;
private ButtonField srvButton = new ButtonField("Service Call");

public HelloWorldScreen() {
super();
System.out.println("Adding text");
LabelField title = new LabelField("HelloWorld Sample",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
setTitle(title);
textField = new RichTextField("Hello World!");
add(textField);
System.out.println("Added text");

srvButton.setChangeListener(listenerSrvButton);
add(srvButton);

}

FieldChangeListener listenerSrvButton = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
String serviceUrl = "h**p://localhost:2715/Service1.asmx";
String serviceNamespace = "h**p://tempuri.org/";
String soapAction = "h**p://tempuri.org/HelloWorld";
String serviceMethod = "HelloWorld";

HttpTransport ht = new HttpTransport(serviceUrl);
ht.debug = true;
ht.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");

SoapObject rpc = new SoapObject(serviceNamespace, serviceMethod);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);

// envelope.setOutputSoapObject(rpc);

System.out.println("Created envelope");
envelope.bodyOut = rpc;
envelope.dotNet = true;
envelope.encodingStyle = SoapSerializationEnvelope.XSD;
/*
* envelope.encodingStyle = SoapSerializationEnvelope.ENC;
* envelope.encodingStyle = SoapSerializationEnvelope.XSI;
*/

// rpc.addProperty("Celsius", "12");
String result = "";
try {

ht.call(soapAction, envelope);
result = (envelope.getResponse()).toString();
System.out.println(result);// for debugging
net.rim.device.api.ui.component.Dialog.alert(envel ope
.getResponse().toString());

} catch (XmlPullParserException ex) {
String msg = ex.toString();
System.out.println(msg);
} catch (Exception ex) {
System.out.println("i am here in catch");
System.out.println(ex.getMessage());
// String msg = ex.toString();

}
textField.setText(result);
// ((HelloWorldScreen)this.getActiveScreen()).setScre enTest(result);
}
};

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

public boolean onClose() {
Dialog.alert("Goodbye!");
System.exit(0);
return true;
}
}
Offline   Reply With Quote