0

I am working in a proxy based environment, where I am not able to consume SOAP web service through emulator. Does anyone know how to consume SOAP web service in a proxy based environment?

I have created this class:

import java.io.IOException;
import java.net.Proxy;
import org.kobjects.base64.Base64;
import org.ksoap2.transport.HttpTransportSE;
import org.ksoap2.transport.ServiceConnection;
//class to handle authentication in a proxy based environment

public class HttpTransportBasicAuth extends HttpTransportSE {
//username and password for accessing a proxy based network
        private String username;
        private String password;
  public HttpTransportBasicAuth(String url, String username, String password) {
    super(url);
    this.username = username;
    this.password = password;
  }

  @Override
  public ServiceConnection getServiceConnection() throws IOException {
    ServiceConnection serviceConnection = super.getServiceConnection();
    addBasicAuthentication(serviceConnection);
    return serviceConnection;
  }

  protected void addBasicAuthentication(ServiceConnection serviceConnection) 
      throws IOException {

    if (username != null && password != null) {
      StringBuffer buffer = new StringBuffer(username);
      buffer.append(':').append(password);
      byte[] bytes = buffer.toString().getBytes();
      buffer.setLength(0);
      buffer.append("Basic ");
      Base64.encode(bytes, 0, bytes.length, buffer);
      serviceConnection.setRequestProperty
        ("Authorization", buffer.toString());
    }
  }

}

and then I created its object like:

HttpTransportBasicAuth androidHttpTransportSE = new HttpTransportBasicAuth(url); androidHttpTransportSE.call(url);

but its returning null pointer exception, I am not able to findout what could be the solution to access webservice in a proxy based network..Please help

Thanks in advance

androidDev
  • 1,179
  • 4
  • 13
  • 31
  • How are you consuming the soap based webservices? Can you show your code snippet? – karthick Oct 08 '13 at 08:41
  • SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); request.addProperty("device_id", "0:0:0:0:0"); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11);envelope.dotNet=true; envelope.setOutputSoapObject(request); System.out.println("Envelope===>"+envelope.bodyOut.toString()); androidHttpTransport.debug=true; androidHttpTransport.call(SOAP_ACTION, envelope); SoapObject obj = (SoapObject)envelope.bodyIn; System.out.println(obj.toString()); – androidDev Oct 08 '13 at 08:48
  • Can you use HttpTransportSE instead of androidHttpTransport. Refer this http://stackoverflow.com/questions/5674851/error-in-calling-web-service – karthick Oct 08 '13 at 08:59
  • androidHttpTransport is an object of HttpTransportSE – androidDev Oct 08 '13 at 09:41

0 Answers0