BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 06-24-2010, 04:15 PM   #1 (permalink)
New Member
 
Join Date: Jun 2010
Model: 7100T
PIN: N/A
Carrier: Telus
Posts: 3
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default KSoap - passing parameters

Please Login to Remove!

Hi,

I'm trying to get a call to a free public web service to work using KSoap.
It works on services without parameters, but as soon as I try to introduce a parameter it fails with the following message:

Code:
XCEPTION: SoapFault - faultcode: 'soap:Server' faultstring: 'System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Data.SqlClient.SqlException: Procedure or function 'GetBibleWordsbyKeyWord' expects parameter '@BibleWords', which was not supplied.
   at WebServicex.BibleWebservice.GetBibleWordsbyKeyWord(String BibleWords)
   --- End of inner exception stack trace ---' faultactor: 'null' detail: org.kxml2.kdom.Node@16a55fa
My code is as follows:

Code:
	public static void main(String[] args) {
	       
		
			String serviceUrl = "webservicex.net/BibleWebservice.asmx";  
			String serviceNameSpace = "webserviceX.NET";  
			String soapAction = "webserviceX.NET/GetBibleWordsbyKeyWord ";  
			String methodName = "GetBibleWordsbyKeyWord  "; 

			
	        SoapObject sub = new SoapObject(serviceNameSpace, methodName);

	        sub.addProperty("BibleWords", "Enoch");
	        
	        SoapSerializationEnvelope envelope = new  SoapSerializationEnvelope(SoapEnvelope.VER11);  
	        envelope.bodyOut = sub;  
	        System.out.println(envelope.bodyOut.toString());
	        envelope.encodingStyle = SoapSerializationEnvelope.ENC;  
	        HttpTransportSE ht = new HttpTransportSE(serviceUrl);  
	        ht.debug = true;  
	        ht.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
	        try  {  
	        	ht.call(soapAction, envelope);  
	        	Object result = (envelope.getResponse());  
	        	System.out.println("kSOAP response: " + result.toString());
	        }  
	       catch(org.xmlpull.v1.XmlPullParserException ex2){  
	    	   System.out.println("EXCEPTION: " + ex2.getMessage());
	       }  
	       catch(Exception ex){  
	    	   String bah = ex.toString();  
	    	   System.out.println("EXCEPTION: "+bah);
	    	   System.out.println("HT REQUEST DUMP" + ht.requestDump);

	       }  
		}
Any help would be greatly appriciated.
Since I am new to this forum I have had to remove http: // www from all URLS above.
Offline  
Old 06-24-2010, 04:27 PM   #2 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2010
Model: 8530
PIN: N/A
Carrier: Sprint
Posts: 48
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is working code from my small project. Hope it will help you.

//passing strings and returns EmployeeResponse object
FieldChangeListener employeeListener = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
String serviceUrl = "http : //servername/service1.asmx";
String serviceNamespace = "http : //tempuri.org/";
String soapAction = "http : //tempuri.org/GetEmployeeDetail";
SoapObject rpc = new SoapObject(serviceNamespace,"GetEmployeeDetail");
rpc.addProperty("EmployeeID", "123");
rpc.addProperty("EmployeeName", "MyName");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.bodyOut = rpc;
// envelope.dotNet = true;
envelope.encodingStyle = SoapSerializationEnvelope.XSD;
envelope.addMapping("http : //tempuri.org/encodedTypes",
"EmployeeResponse", new EmployeeResponse().getClass());

envelope.setOutputSoapObject(rpc);
HttpTransport ht = new HttpTransport(serviceUrl);
ht.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
ht.debug = true;
try {
ht.call(soapAction, envelope);
EmployeeResponse myObj = (EmployeeResponse) envelope
.getResponse();
add(new RichTextField("ID: " + myObj.EmpID + "\n" + "Name: "
+ myObj.EmpName + "\n" + "Phone: " + myObj.Phone + "\n"+ "Address: " + myObj.Address));
} catch (Exception ex) {
String msg = ex.toString();
System.out.println(msg);
add(new RichTextField("Error Message: " + msg));
}
}
};

Last edited by romah : 06-24-2010 at 04:29 PM.
Offline  
Old 06-25-2010, 08:45 AM   #3 (permalink)
New Member
 
Join Date: Jun 2010
Model: 7100T
PIN: N/A
Carrier: Telus
Posts: 3
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, I'll give it a try
Offline  
Old 06-25-2010, 09:49 AM   #4 (permalink)
New Member
 
Join Date: Jun 2010
Model: 7100T
PIN: N/A
Carrier: Telus
Posts: 3
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I got it to work.
It turned out that I was missing:

Code:
envelope.dotNet = true;
Thanks again
Offline  
Old 06-25-2010, 10:06 AM   #5 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2010
Model: 8530
PIN: N/A
Carrier: Sprint
Posts: 48
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

You're welcome.
Offline  




Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.