1

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
idiaz
  • 21
  • 1
  • 6

1 Answers1

0

This is a wonderful tutorial shows you how to use Ksoap and .net webservices together. step by step author writes the code (such as soap object, envelop, then tranport etc etc).

Good luck.

Jay Mayu
  • 17,023
  • 32
  • 114
  • 148
  • Thank you for your quick answer. However i want to know how to pass credentials using ksoap2 to a .net web service that has as authentication method "form" (I'm using an aspx file) – idiaz Aug 16 '11 at 16:58
  • make your question more clear by adding code snippets and exception or wotever from logcat then people here would be able to help you. The infomration given is insufficient buddy. – Jay Mayu Aug 16 '11 at 17:11
  • I hope you understand better my question. i'm with this since last week and any help is going to be usefull – idiaz Aug 17 '11 at 16:14