Android connecting to soap web-service with digest authentification using ksoap - android

I am having problems to get the Authorization headers from a PHP soap web-service with DIGEST authentification. (PHP client works correctly with the web-service).
I get error 401, but I cant find the header in the envelope. The headerIn field is empty.
I need to connect somehow to the web-service - get the headers (main problem) and then recreate the Digest authorization header (which is easy) and connect again to web-service with the authentification informations.
Any advice?
#Override
protected String doInBackground(SoapProperty... soapProperties) {
if(this.methodName.isEmpty())
throw new IllegalArgumentException("methodName is not specified");
String response="";
android.os.Debug.waitForDebugger();
try{
String SOAP_ACTION = this.namespace + "/" + this.methodName;
SoapObject request = new SoapObject(this.namespace, this.methodName);
for(SoapProperty s : soapProperties){
request.addProperty(s.getKey(), s.getValue());
}
SoapSerializationEnvelope envelope;
envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE ht = new HttpTransportSE(this.url);
ht.call(SOAP_ACTION, envelope);
response = (String)envelope.getResponse();
}
catch(Exception e){
e.printStackTrace();
publishProgress(true);
}
return response;
}

Related

Connect to Exchange using Ksoap2 for android

I am trying to use ksoap2 to connect to an exchange web server to create an email app in android. So far I have very little to go on since Microsoft doesn't give a straight forward explanation of how to use the autodiscover soap methods. So far this is all I have
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
String userpass = username+password;
NTCredentials cred = new NTCredentials(userpass);
I am using Android API 21 since it still has the NTCredentials methods. My question then is how do I connect to an exchange server. And then is there anything else I need to do to view email or send email. My app already can show the inbox for a imap or pop3 mail client so can I just connect to the exchange server using ksoap then just use the already defined methods for imap and pop3 to do everything else?
As I mentioned in the comments above I have not done this before, but i have used ksoap2 a bit, so i would try something like this:
String NAMESPACE = "http://www.namespace.com/";
String METHOD_NAME = "MethodName";
String SOAP_ACTION = NAMESPACE+METHOD_NAME;
String URL = "https://www.namespace.com/services/Service.asmx";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
// Set all input params
request.addProperty("property", "value");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
// Enable the below property if consuming .Net service
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try
{
List<HeaderProperty> headerList = new ArrayList<HeaderProperty>();
//I would use this for authentication
headerList.add(new HeaderProperty("Authorization", "Basic " + Base64.encode((username+":"+password).getBytes())));
androidHttpTransport.call(SOAP_ACTION, envelope, headerList);
SoapObject response = (SoapObject)envelope.getResponse();
}
catch(Exception e)
{
}
This is Basic authentication.

Junk values are added in json response when consuming soap web-service in android

I am consuming soap web service to get data response from server is proper json (checked on server side ) but when i get this response in android some junk values are added in it
here is the junked response
{"error":"0","message":"Record found.","user_info":"[{\"UserId\":\"465\",\"Name\":\"ENG ABDALLA M SHEIKH\",\"Email\":\"amsheik#gmail.com\",\"Tel\":\"+971507344068\",\"Balance\":\"100\"}]"}
in the above response you can see slashes() and extra quotes(") are added
here is my soap code
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("username", "user01");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,30000);
androidHttpTransport.debug = true;
SoapPrimitive response = null;
try {
//Invole web service
androidHttpTransport.call(SOAP_ACTION+method_name, envelope);
//Get the responseS
response = (SoapPrimitive) envelope.getResponse();
Log.e("relust", ""+response);
} catch (Exception e) {
e.printStackTrace();
}
Note response is in proper json tested from php
That's not junk, but standard syntax for Unicode encoding. You can convert to UTF-8 to make those characters go away.

Connect to a Delphi WebService with Android

I wrote a simple webservice in Delphi XE
It is running on IIS, as ISAPI Dll.
I cant connect to this webservice with Android:
private final String NAMESPACE = "http://217.114.221.83/grigliamo/";
private final String URL = "http://217.114.221.83/grigliamo/DifferenziaWS.dll/wsdl/IWSDifferenzia";
private final String SOAP_ACTION = "http://217.114.221.83/grigliamo/WS_Login";
private final String METHOD_NAME = "WS_Login";
public void getWebService(String x) {
//Create request
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
//Involve web service
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
Assign it to fahren static variable
Res = response.toString();
} catch (Exception e) {
Res = e.toString();
e.printStackTrace();
}
}
I always get an org.xmlpull.v1.XmlPullParserException: expectd START_TAG
Can anybody tell me what's wrong on my webservice please?
Thanks
Andrea
Nothing is wrong with the web service, SoapUI can retrieve the WSDL and send login requests.
I recommend to read ksoap2 org.xmlpull.v1.xmlpullparserexception expected start_tag error
The answers there contain step-by-step guides to build the correct SOAP request parameters / properties for a web service.

How to call a nav webservice from android

I want to call web service running in Microsoft Dynamics nav ERP i am using ksoap2 library but problem is every time i run my application it throws
java.net.ConnectException: localhost/127.0.0.1:7047 - Connection refused
Microsoft Dynamics nav is using NTLM authentication may that is the problem, please give any suggestion to solve it.
Thanks in advance.
My code is
String namespace = "urn:microsoft-dynamics-schemas/codeunit/NavisionWS";
String url = "http://localhost:7047/DynamicsNAV/WS/Codeunit/NavisionWS";
String soap_action = "urn:microsoft-dynamics-schemas/codeunit/NavisionWS:GetLoginInfo";
String method_name = "GetLoginInfo";
try
{
SoapObject request = new SoapObject(namespace, method_name);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE transport = new HttpTransportSE(url);
transport.call(soap_action, envelope); // Receive Error here!
SoapObject result = (SoapObject) envelope.getResponse();
great = result.toString();
}
catch (Exception e)
{
e.printStackTrace();
great = e.toString();
Toast.makeText(this, great, Toast.LENGTH_LONG).show();
}
Use IP Address instead of Localhost to connect to webservice from Android
Have you added <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> to your manifest?

soap 1.2 android Please supply a valid soap action

My .net webservice is apparently running soap 1.2 (by checking the .wsdl) and ive been trying to access the helloworld webservice for testing but i have encountered errors.
Im trying to do this via the emulator by the way.
So when I use soap 1.2 version , i get the error that it is "unable to handle request without a valid action parameter. Please supply a valid soap"
I want to know what I am missing and what should I do.
Thank you!
Things I have already done:
Add permission for android to use the internet
Change from Soap version 1.1 and 1.2
Change from SoapObject to Object (for both soap 1.1 and 1.2)
Used 10.0.2.2 for the emulator
Checked for errors in spelling in the addresses and method names
My codes:
private static final String NAMESPACE = "http://localhost/WebService/";
private static final String URL = "http://10.0.2.2:1672/Eventurous/WsEventurousMobile.asmx";
private static final String HelloWorld_SOAP_ACTION = "http://localhost/WebService/HelloWorld";
private static final String METHOD_NAME1 = "HelloWorld";
...
...
public static String GetHelloWorld() {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME1);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER12);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,60000);
try {
androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
androidHttpTransport.call(HelloWorld_SOAP_ACTION, envelope);
SoapObject response = (SoapObject)envelope.getResponse();
String result = response.getProperty(0).toString();
return result;
} catch (Exception e) {
return e.toString();
}
}
Error for Soap version 1.2
Code: soap:Sender, Reason: System.Web.Services.Protocols.SoapException: Unable to handle request without a valid action parameter. Please supply a valid soap action.
at System.Web.Services.Protocols.Soap12ServerProtocolHelper.RouteRequest()
at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message)
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean
Error for Soap version 1.1
SoapFault - faultcode: 'soap:Client' faultstring: 'System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: http://localhost/WebService/HelloWorld.
at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()
at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message)
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)' faultactor: 'null' detail: org.kxml2.kdom.Node#413c9098
use
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
instead of
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER12);
and remove this line androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
and instead of SoapObject response = (SoapObject)envelope.getResponse();
use SoapObject response = (SoapObject)envelope.bodyIn;
It will Help you.If still get Error then Write me.

Categories

Resources