i am trying to set up connection to SOAP WebService from Android app but every time i get wried error in my result : object reference not set to an instance of an object java It seems to be error from server --> SOAP Webservice call from Java gives "Object reference not set to an instance of an object"
But when i try it throught web browser with POST request it works fine :)
This service http://ws.cdyne.com/ip2geo/ip2geo.asmx?op=ResolveIP
private static String NAMESPACE = "http://ws.cdyne.com/";
private static String URL = "http://ws.cdyne.com/ip2geo/ip2geo.asmx";
private static String SOAP_ACTION = "http://ws.cdyne.com/";
public static String invokeHelloWorldWS(String name, String webMethName) {
String resTxt = null;
SoapObject request = new SoapObject(NAMESPACE, webMethName);
PropertyInfo sayHelloPI = new PropertyInfo();
// Set name
sayHelloPI.setName("ipAddress");
// Set Value
sayHelloPI.setValue("88.212.35.129");
// Set dataType
sayHelloPI.setType(String.class);
// Add the property to request object
request.addProperty(sayHelloPI);
// Create envelope
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
// Set output SOAP object
envelope.setOutputSoapObject(request);
// Create HTTP call object
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try{
// Invoke web service
androidHttpTransport.call(SOAP_ACTION+webMethName, envelope); //webMethName = "ResolveIP"
// Get the response
Log.d("a", androidHttpTransport.responseDump);
//SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
// Assign it to resTxt variable static variable
//resTxt = response.toString();
}catch(Exception e){
//Print error
e.printStackTrace();
}
}
I spend lot of time on google but i cant figure right answer why this happend
// EDIT Finally i get it right ... idk why but when i send second parameter like this (i reuse old property) :
sayHelloPI.setName("licenseKey");
sayHelloPI.setValue("some_key");
sayHelloPI.setType(String.class);
request.addProperty(sayHelloPI);
it wasnt working. But when i make new Property object it works:
PropertyInfo sayHelloPI1 = new PropertyInfo();
sayHelloPI1.setName("licenseKey");
sayHelloPI1.setValue("ds");
sayHelloPI1.setType(String.class);
request.addProperty(sayHelloPI1);
Maybe it help someone next time