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
New Developer
Posts: 17
Registered: ‎07-16-2012
My Device: None
My Carrier: None

Struggling to connect to a .NET webservice using ksoap2

Hi all,

 

Im trying to connect to a .NET webserive and I keep getting the error message "unexpected type (position:END_DOCUMENT null@1:0".

 

The current web service is using .NET  and in the web config file, it was set as wsHTTPBinding, if that is important.

 

When i connect via SoapUI it worked perfectly fine but needed to add WS-A addressing.

 

 

Main File:

 

        String soap_action = actionname;
    	SoapObject request = new SoapObject("http://tempuri.org/", methodname);
    	
    	MapGetLocalAuthorityCode param1 = new MapGetLocalAuthorityCode();
    	
    	param1.code = "000000-8BE8-4039-8185-1111111111";
    	param1.messageid = "";
    	param1.partner = "Met";

    	PropertyInfo pi = new PropertyInfo();
        pi = new PropertyInfo();
        pi.name = "header";
        pi.type = param1.getClass(); 
        
        request.addProperty(pi , param1);          

    	// Build envelope , 
    	SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);// Soap version must match server implementation
    	envelope.dotNet = true; // Must set this if the server is implemented on the dotnet framework
    	envelope.implicitTypes = true;
    	envelope.setOutputSoapObject(request);
    	envelope.encodingStyle = "utf-8";
    	
    	//MapResponse mr = new MapResponse();
    	
    	envelope.addMapping("http://tempuri.org/", "header", param1.getClass());
    	//envelope.addMapping("http://tempuri.org/", "Response", mr.getClass());
    	
    	HttpTransport ht = new HttpTransport(webserviceurl);
    	ht.debug = true; 
    	String result;
    	  try
    	  {
    		 ht.call(soap_action, envelope);
    		 //MapResponse response = readEnvelope((SoapObject)envelope.getResponse());
    		 //result = "Test: "+response.response_description + response.response_number + response.xsd_version;
    		 //result = ""+response;
    		 result ="working";
    	  }
    	  catch (Exception e)
    	  {
    		  result  = "Error:"+e.toString();
    		  result += "Message:"+e.getMessage();
    	  }
    	return result;

 

 MapGetLocalAuthorityCode Class

 

package mypackage;

import java.util.Hashtable;

import org.ksoap2.serialization.PropertyInfo;

public class MapGetLocalAuthorityCode extends BaseMap
{
	//public static Class<? extends MapRequestSessionManagement> MAPREQUESTSESSIONMANAGEMENT_CLASS = new MapRequestSessionManagement().getClass();    
	public String code;
	public String messageid;
	public String partner;
	
	public int getPropertyCount()
	{
		return 3;
	}
	public Object getProperty(int index)
	{
		switch (index)
		{
			case 0:
				return code;
			case 1: 
				return messageid;
			case 2: 
				return partner;
			default:
				return null;
		}
	}
	public void getPropertyInfo(int index, Hashtable properties, PropertyInfo info)
	{
		switch (index)
		{
			case 0:
				info.type = PropertyInfo.STRING_CLASS;
				info.name = "Code";
				break;
			case 1:
				info.type = PropertyInfo.STRING_CLASS;
				info.name = "MessageID";
				break;
			case 2:
				info.type = PropertyInfo.STRING_CLASS;
				info.name = "Partner";
				break;
			default:
				break;
		}
	}
	public void setProperty(int index, Object value)
	{
		switch (index)
		{
			case 0:
				code = value.toString();
				break;
			case 1: 
				messageid = value.toString();
				break;
			case 2: 
				partner = value.toString();
				break;
			default:
				break;
		}
	}
}

 

Developer
Posts: 17,019
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Struggling to connect to a .NET webservice using ksoap2

you get a http response code, and ksoap2 is not able to handle it on its own.

my first suggestion is to use j2se to develop the webservice. you can use HttpTransportSE, otherwise the code is the same.

to enable handling the response code you have to overwrite ServiceConnectionMidp (source is available at the project site).
we check the response code at the openInputStream method, log it and throw an exception.
otherwise ksoap tries to parse the http response message with kxml, which fails as it is html, not xml.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
New Developer
Posts: 17
Registered: ‎07-16-2012
My Device: None
My Carrier: None

Re: Struggling to connect to a .NET webservice using ksoap2

Hi Simon,

 

I got the source code from the project site but is there a project example using the ServiceConnectionMidp and openInputStream method.

 

Stephen

Highlighted
Developer
Posts: 17,019
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Struggling to connect to a .NET webservice using ksoap2

not that i know of, maybe you find something on the web.
connection.getResponseCode == HttpConnection.HTTP_OK is not that difficult to code though...
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter