I have an android app that consumes a .Net web service for that i'm using ksoap2. I want to pass credentials (username and password) so I' need to use a type of authentication (form, Basic, ...), but i don't know how.
I had download a secure WebService (this sample ask for credentials) from: Web Services Security
[WebMethod]
public string HelloWorld()
{
return "Hello " + Context.User.Identity.Name;
}
I call the webMethod with basic code and that's why i get an error, somewhere i need to pass username and password but i don't know how. There are links related, that use NTCredentials, envelope.headerOut and HeaderProperty (Class that i don't have), i try all and nothing.
public String getStringWebService()
{
String namespaceServicio;
String nombreMetodo;
namespaceServicio = "http://tempuri.org/";
nombreMetodo = "HelloWorld";
accionSoap = namespaceServicio + nombreMetodo;
urlServicio = "http://???.???.???/Prueba/Autenticacion/AuthTestSvc/Service1.asmx";
SoapObject request = new SoapObject(namespaceServicio, nombreMetodo);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.bodyOut = request;
envelope.dotNet = true;
envelope.encodingStyle = SoapEnvelope.XSD;
HttpTransportSE ht = new HttpTransportSE(urlServicio);
ht.debug = true;
String cad = "";
try
{
String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
" <soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
" <soap:Header>" +
" <AUTHHEADER xmlns=\"http://tempuri.org/\" />" +
" <username>test</username> " +
" <password>test</password> " +
" </AUTHHEADER> " +
" </soap:Header> " +
" <soap:Body> " +
" <SENSITIVEDATA xmlns=\"http://tempuri.org/\"> " +
" </soap:Body> " +
" </soap:Envelope> ";
ht.setXmlVersionTag(xml);
ht.call(accionSoap, envelope);
cad = ht.responseDump;
return cad;
}
catch(Exception e)
{
throw new Exception(e.toString());
}
}
The exception occurs in httpTransportSE.call(soapAction, envelope), because as i say i'm not passing the username and password
org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/envelope/}Envelope (position:START_TAG <html>@1:6 in java.io.InputStreamReader@44f13428)
In ht.responseDump I get in html Code:
401 - Unauthorized: Access is denied due to invalid credentials.
You do not have permission to view this directory or page using the credentials that you supplied