Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 47
Registered: ‎11-11-2009
My Device: Not Specified

.NET 3.5 Web Service and KSoap Anomaly. Can Someone Help?

I am currently developing a BlackBerry application which consumes .NET 3.5 Web Service (built using Visual Studio 2008). I'm having a problem with my KSoap implementation. My application can call the service function and get the return value, but It cannot send any value to the parameter. The code here just return " | | | | | | " without any value printed. :smileysad: can someone help?

 

The .NET 3.5 Web Service

 

namespace CommBook.Services
{
    /// <summary>
    /// Summary description for WebService
    /// </summary>
    [WebService(Namespace = "http://www.binus.edu")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class WebService : System.Web.Services.WebService
    {
        [WebMethod]
        public string ParentSendMessage(string pin, string studentId, string teacherId, string teacherEmail, string messageSubject, string messageContent, string messageType)
        {
            return pin + " | " + studentId + " | " + teacherId + " | " + teacherEmail + " | " + messageSubject + " | " + messageContent + " | " + messageType;
        }
    }
}

 

 

 

The Web Service Connection (Using KSoap) Class

 

public class WebServiceConnection
{
	private String action;	 // Function to be called
	private String result;	 // Output
	private SoapObject soap; // SOAP object
	private SoapSerializationEnvelope envelope; // Serialization envelope
	private HttpTransport httpTransport; // Data transport over HTTP
	
	/**
	 * Default constructor for WebServiceConnection class
	 */
	public WebServiceConnection(String url, String namespace, String functionName)
	{
		// Initialization
		action 			= namespace+functionName;
    	soap 			= new SoapObject(namespace, functionName);
    	envelope 		= new SoapSerializationEnvelope(SoapEnvelope.VER11);
    	httpTransport 	= new HttpTransport(url);
    	
    	envelope.bodyOut = soap;
    	envelope.dotNet = true;
    	envelope.encodingStyle = SoapSerializationEnvelope.XSD; 
    	
    	// Set HTTP Transport debugging mode
    	httpTransport.debug = true;
	}
	
	/**
	 * Connect to web service
	 */
	public boolean Connect()
	{
		try
		{
			// Call the web service
			httpTransport.call(action, envelope);
			// Get the return value
			try
			{
				result = envelope.getResponse().toString();
			}
			catch(SoapFault soapException)
			{
				result = soapException.toString();
				return false;
			}
		}
		catch(IOException ioException)
		{
			// Connection time-out
			System.err.println(ioException.toString());
			result = "[EXCEPTION]" + ioException.toString();
			return false;
		}
		
		return true;	
	}
	
	/**
	 * Add required parameters
	 */
	public void AddParameter(String parameter, Object value)
	{
		soap.addProperty(parameter, value);
	}
	
	// Mengambil return value dari action yang dipanggil
	public String GetResponse()
	{
		return result;
	}
}

 

 

This is how I use the connection class:

 

String serviceMethod = "ParentSendMessage";
WebServiceConnection connection = new WebServiceConnection(CommBookApplication._serviceURL, CommBookApplication._serviceNamespace, serviceMethod);
		
// Add connection parameters
connection.AddParameter("pin", Integer.toHexString(DeviceInfo.getDeviceId()));
connection.AddParameter("studentId", "4");
connection.AddParameter("teacherId", "3");
connection.AddParameter("teacherEmail", "mail@domain.com");
connection.AddParameter("messageSubject", "Subject");
connection.AddParameter("messageContent", "Content");
connection.AddParameter("messageType", "1");
		
// Connect
if(connection.Connect())
{
	commBookApplication.saveToOutbox(message);
			
	synchronized(UiApplication.getEventLock()) 
	{
		// Error in status.show
		Status.show("Your message has been sent.");
		commBookApplication.getActiveScreen().close();
	}
}

 

 

 

Developer
Posts: 47
Registered: ‎11-11-2009
My Device: Not Specified

Re: .NET 3.5 Web Service and KSoap Anomaly. Can Someone Help?

Finally gets it done.

 

The problem is caused by the namespace. If the namespace contains http:// it will cause the anomaly.

 

Changing it to something without Http will make it work.

Contributor
Posts: 32
Registered: ‎06-26-2010
My Device: all
My Carrier: stc

Re: .NET 3.5 Web Service and KSoap Anomaly. Can Someone Help?

[ Edited ]

Ok

I add Ksoap library as mention here

http://www.blackberryforums.com/developer-forum/200894-using-ksoap2-blackberry-tutorial-one-without-...

then I copy and  use  WebServiceConnection class

 

when I run it in simulator I det this error

ksoap2-j2me-core-prev-2.1.2 not found

 

 

Contributor
Posts: 32
Registered: ‎06-26-2010
My Device: all
My Carrier: stc

Re: .NET 3.5 Web Service and KSoap Anomaly. Can Someone Help?

I think it is solved after I check this note some where

 

"Common problems may include “Error Starting Sample: Module ‘ksoap2-j2me-core-prev-2.1.2’ not found.” I struggled with this for some time. Go back and retrace your steps, you’ve skipped over something. Even though it compiles fine within Eclipse the ksoap jar has not been deployed to the device along with the rest of your code. I have noticed an annoyance where the KSoap jar will be removed from the Properties > Java Build Path “Libraries” and “Order and Export” tabs if you make any further changes to the “BlackBerry Project Properties”. You’ll have to go back in and re-add the jar."

Contributor
Posts: 32
Registered: ‎06-26-2010
My Device: all
My Carrier: stc

Re: .NET 3.5 Web Service and KSoap Anomaly. Can Someone Help?

Hello   and all

 

kindly I wanna ask in your replay you said "the namespace contains http:// it will cause the anomaly.Changing it to something without Http will make it work" so something else like what ?

 

maybe urn ? if yes I know that You can get the URN of your web service from the web service's WSDL. but when I open the wsdl I can't get it ,

 

any suggestion ? thanks

Developer
Posts: 47
Registered: ‎11-11-2009
My Device: Not Specified

Re: .NET 3.5 Web Service and KSoap Anomaly. Can Someone Help?

I tried something like "CommunicationBookService" as the namespace, and it worked! :smileyhappy:

Contributor
Posts: 15
Registered: ‎06-11-2010
My Device: Pearl 8130
My Carrier: verizon

Re: .NET 3.5 Web Service and KSoap Anomaly. Can Someone Help?

Hi...

 

I tried several samples online and I cannot get success in this topic.

I am using ksoap2, webservice NET 4.0 (visual studio 2010), eclipse 3.5 clasic, plug-in 4.3 and 8300 simulator.

I run a code like posted in this topic and I got this error:

org.xmlpull.v1.XmlpullParserException:unexpected type(position:TEXT Connection refus...@1:30 in java.in.InputStreamReader@61ccda)

I have twice error with different number at the end @6c002d46

 

Please, can somebody help me with this or show me a sample that works...

 

Thanks a lot...

 

 

Contributor
Posts: 15
Registered: ‎06-11-2010
My Device: Pearl 8130
My Carrier: verizon

Re: .NET 3.5 Web Service and KSoap Anomaly. Can Someone Help?

ok... I got it.. it is working... :smileyvery-happy:

New Member
Posts: 1
Registered: ‎08-29-2010
My Device: Not Specified

Re: .NET 3.5 Web Service and KSoap Anomaly. Can Someone Help?

Can i get the code ?

Contributor
Posts: 15
Registered: ‎06-11-2010
My Device: Pearl 8130
My Carrier: verizon

Re: .NET 3.5 Web Service and KSoap Anomaly. Can Someone Help?

 this is a good tutorial and include the code files...

 

http://www.craigagreen.com/index.php?/Blog/blackberry-and-net-webservice-tutorial-part-1.html