Android KSOAP2 Error - android

I am using the jar(ksoap2-android-assembly-2.6.5-jar-with-dependencies) and have a web -
services.url = http://62.244.199.18:8888/ergo-ergoService-context-root/ergoSoapHttpPort?WSDL
and my code is below
private static final String METHOD_NAME = "checkloginnew";
private static final String SOAP_ACTION = "http://ergoconn/Ergo.wsdl/checkloginnew";
private static final String NAMESPACE = "http://ergoconn/Ergo.wsdl";
private static final String URL = "http://62.244.199.18:8888/ergo-ergoService-context-root/ergoSoapHttpPort?WSDL";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo pi = new PropertyInfo();
pi.setName("pPid");
pi.setValue(1149688);
pi.setType(BigDecimal.class);
request.addProperty(pi);
PropertyInfo pi2 = new PropertyInfo();
pi2.setName("pPass");
pi2.setValue("074920");
pi2.setType(String.class);
request.addProperty(pi2);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(URL);
httpTransport.debug = true;
httpTransport.call(SOAP_ACTION, envelope);
SoapObject result=(SoapObject)envelope.getResponse();
But I get an error "Caught exception while handling request: unrecognized operation: {http://ergoconn/Ergo.wsdl}checkloginnew"
In my httpTransport.responseDump:
<faultcode>env:Client</faultcode><faultstring>Caught exception while handling request: unrecognized operation: {http://ergoconn/Ergo.wsdl}checkloginnew</faultstring></env:Fault>
Thanks very much

Related

SOAP Calling using Ksoap

I have a SOAP Url http://seycel.com.mx/ws/res2.php I need to call method deposito with 4 parameter from, origin, key word, timestamp.
What I am trying-
private static final String SOAP_ACTION = "urn:recargas#recharge";
private static final String METHOD_NAME = "deposito";
private static final String NAMESPACE = "urn:recargas";
private static final String URL = "http://seycel.com.mx/ws/res2.php";
public int GetInteger2() throws IOException, XmlPullParserException {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo pi = new PropertyInfo();
pi.setName("from");
pi.setValue(9239392939);
request.addProperty(pi);
SoapSerializationEnvelope envelope =
new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
return Integer.parseInt(result.toString());
}
But getting error in From value Integer no is too large Can any one guide me how to call that method with those 4 parameter for origin value it should be 1212121212

android-ksoap2 request results in HTTP 500

I am trying to use the web service described in https://swea.riksbank.se/sweaWS/wsdl/sweaWS_ssl.wsdl
I have written the following test code:
private static final String NAMESPACE = "http://swea.riksbank.se/ws";
private static final String METHOD_NAME = "getInterestAndExchangeGroupNames";
private static final String SOAP_ACTION = NAMESPACE + "/" + METHOD_NAME;
private static final String URL = "https://swea.riksbank.se:443/sweaWS/services/SweaWebServiceHttpSoap12Endpoint";
private void testService(){
HttpTransportSE androidHttpTransport = null;
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo groupid = new PropertyInfo();
groupid.setValue(5);
groupid.setType(PropertyInfo.INTEGER_CLASS);
groupid.setName("groupid");
PropertyInfo languageid = new PropertyInfo();
languageid.setValue("sv");
languageid.setType(PropertyInfo.STRING_CLASS);
languageid.setName("languageid");
request.addProperty(groupid);
request.addProperty(languageid);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.dotNet = false;
envelope.setOutputSoapObject(request);
androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION, envelope);
//SoapObject result = (SoapObject)envelope.getResponse();
}
catch (Exception e) {
Log.e("SOAP_TEST", "========= Request start =========");
Log.e("SOAP_TEST", androidHttpTransport.requestDump);
Log.e("SOAP_TEST", "========== Request end ==========");
Log.e("SOAP_TEST", "========= Response start ========");
Log.e("SOAP_TEST", androidHttpTransport.responseDump);
Log.e("SOAP_TEST", "========== Response end =========");
Log.e("SOAP_TEST", e.toString());
Log.e("SOAP_TEST", e.getMessage());
}
}
The test code will result in HTTP status 500
When I check the request dump the request xml looks like this:
<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://www.w3.org/2003/05/soap-encoding" xmlns:v="http://www.w3.org/2003/05/soap-envelope">
<v:Header />
<v:Body>
<n0:getInterestAndExchangeGroupNames id="o0" c:root="1" xmlns:n0="http://swea.riksbank.se/ws">
<groupid i:type="d:int">5</groupid>
<languageid i:type="d:string">sv</languageid>
</n0:getInterestAndExchangeGroupNames>
</v:Body>
</v:Envelope>
I have also imported the wsdl into soapUI, which will generate the following request:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://swea.riksbank.se/xsd">
<soap:Header/>
<soap:Body>
<xsd:getInterestAndExchangeNames>
<groupid>5</groupid>
<languageid>sv</languageid>
</xsd:getInterestAndExchangeNames>
</soap:Body>
</soap:Envelope>
That request looks exactly as described in the web service documentation and also works as expected.
So what do I need to do to fix the ksoap2 request? (This soap stuff is completely new for me.)
After some updates it now works fine. My working test code looks like this:
private static final String NAMESPACE = "http://swea.riksbank.se/xsd";
private static final String METHOD_NAME = "getInterestAndExchangeNames";
private static final String SOAP_ACTION = NAMESPACE + "/" + METHOD_NAME;
private static final String SOAP_URL = "https://swea.riksbank.se:443/sweaWS/services/SweaWebServiceHttpSoap12Endpoint";
private void testService(){
HttpTransportSE androidHttpTransport = null;
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo groupid = new PropertyInfo();
groupid.setValue(5);
groupid.setName("groupid");
groupid.setNamespace("");
PropertyInfo languageid = new PropertyInfo();
languageid.setValue("sv");
languageid.setName("languageid");
languageid.setNamespace("");
request.addProperty(groupid);
request.addProperty(languageid);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.encodingStyle = SoapEnvelope.ENC;
envelope.setAddAdornments(false);
envelope.implicitTypes = true;
envelope.dotNet = false;
envelope.setOutputSoapObject(request);
androidHttpTransport = new HttpTransportSE(SOAP_URL);
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION, envelope);
...
}

SoapObject in android application

Here is some fragment of my android application code PerformDownload.java
public class PerformDownload {
private final String NAMESPACE = "http://tempuri.org/";
private final String URL = "http://10.0.2.2:4304/Service1.asmx";
public String GetContacts(String username) throws IOException, XmlPullParserException
{
// String result = null;
final String SOAP_ACTION = "http://tempuri.org/GetContacts";
final String METHOD_NAME = "GetContacts";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("username",username);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true; // put this only if the web service is .NET one
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
KvmSerializable response= (KvmSerializable)envelope.bodyIn;
I am getting error on SoapObject,SoapSerializationEnvelope(SoapEnvelope.VER11); and so on.
Why the above code is not accessing soap protocol.

Webservices in android

I am new to android. In my application I tried to call SOAP web services, in that I can't understand what is meant
for(SOAP_Action,OperationName,WSDL_TARGET_NAMESPACE,SOAP_ADDRESS). The following is my full code
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
TextView textView = new TextView(this);
setContentView(textView);
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
OPERATION_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
System.out.println("subbu="+request);
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
try
{
httpTransport.call(SOAP_ACTION, envelope);
Object response = envelope.getResponse();
textView.setText(response.toString());
}
catch (Exception exception)
{
textView.setText(exception.toString());
}
}
}
Can anybody explain what thats purpose for. Give some link from which I can get idea.
SOAP_ACTION / NAMESPACE and METHODS can be found in the WSDL file of the target webservice !
Here is a sample code to send a SOAP request to a webservice :
public class SoapRequest {
private static final String SOAP_ACTION = "xxx";
private static final String METHOD_NAME = "xxx";
private static final String NAMESPACE = "xxx";
private static final String URL = "url of the webservice";
public static SoapObject soap() throws IOException, XmlPullParserException {
SoapObject request = new SoapObject (NAMESPACE, METHOD_NAME);
/* Here you can add properties to your requests */
PropertyInfo pi1 = new PropertyInfo();
pi1.name = "xxx";
pi1.type = String.class;
request.addProperty(pi1, "xxx");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject soapResult = (SoapObject) envelope.bodyIn;
return soapResult;
}

Android : how to pass a integer value to service using KSOAP in android

Not able to pass an integer value to the service request.The value that reaches service request becomes null
Here is my code
private static final String METHOD_NAME ="GetPrivileges";
private static final String NAMESPACE = "http://AuthorizationManagement.ServiceContracts/2007/01/";
private static final String URL ="http://192.168.5.219/NTLS_Authorization
/AuthorisationManager.asmx";
final String SOAP_ACTION ="http://AuthorizationManagement.ServiceContracts/2007/01/GetPrivileges";
public void call() {
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo pi=new PropertyInfo();
pi.type=PropertyInfo.INTEGER_CLASS;
pi.setName("RoleID");
pi.setValue(3);
pi.setNamespace(NAMESPACE);
request.addProperty(pi);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
Object result = envelope.getResponse();
String resultData = result.toString();
public void call(int number)
{
try
{
String METHOD_NAME ="GetPrivileges";
String NAMESPACE = "http://AuthorizationManagement.ServiceContracts/2007/01/";
String URL ="http://192.168.5.219/NTLS_Authorization/AuthorisationManager.asmx";
final String SOAP_ACTION ="http://AuthorizationManagement.ServiceContracts/2007/01/GetPrivileges";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("RoleID",number);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
Object result = envelope.getResponse();
String resultData = result.toString();
Log.v("Result==>",resultData);
}
catch(Exception e)
{
e.printStackTrace();
}
}
simply you can add this
requestObject.addProperty("RoleID",3);
May be try this code //note don't put directly number(3 in ur case) instead pass it as parameter ...
final SoapObject requestObject = new SoapObject(Constants.NAMESPACE,METHOD_NAME );
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = false;
requestObject.addProperty("RoleID",number);
envelope.setOutputSoapObject(requestObject);
AndroidHttpTransport androidHttpTransport =new AndroidHttpTransport(Constants.URL);
try
{
androidHttpTransport.call(Constants.SOAP_ACTION+METHOD_NAME, envelope);
SoapObject response = (SoapObject)envelope.getResponse();
Log.v("result",response.toString());
}
catch(Exception e)
{
e.printStackTrace();
}

Categories

Resources