我試圖設置從Android應用程序到SOAP WebService的連接,但每次在我的結果中出現錯誤錯誤時: 對象引用未設置爲一個Java對象的實例 這似乎是從服務器錯誤 - >SOAP Webservice call from Java gives "Object reference not set to an instance of an object"(JAVA)SOAP WebService錯誤對象引用未設置爲對象的實例
但是當我嘗試它throught網頁瀏覽器POST請求它工作得很好:)
此服務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();
}
}
我花很多時間在谷歌,但我不能算出正確答案,爲什麼這個happend
//編輯 最後我得到它的權利... IDK的爲什麼,但我打發第二個參數是這樣的(我會重新使用舊屬性) :
sayHelloPI.setName("licenseKey");
sayHelloPI.setValue("some_key");
sayHelloPI.setType(String.class);
request.addProperty(sayHelloPI);
它不工作。但是,當我作出新的屬性對象時,它的工作原理:
PropertyInfo sayHelloPI1 = new PropertyInfo();
sayHelloPI1.setName("licenseKey");
sayHelloPI1.setValue("ds");
sayHelloPI1.setType(String.class);
request.addProperty(sayHelloPI1);
也許它幫助別人下次
是你使用ksoap2? – Silverbaq 2014-10-07 22:07:12
是的,我是我的朋友。我知道我可以s send發送從Android的POST請求(因爲從瀏覽器,這種方式工作),我應該工作,但我想發送它像普通肥皂信封 – 2014-10-07 22:08:06