2017-06-24 65 views
0

我嘗試了一個soap weservice示例。 該代碼使用GeoIp webservice從ip地址確定國家。 當我執行代碼時,出現以下異常。運行代碼時未將對象引用設置爲對象execption的實例

例外:

Exception in thread "main" com.sun.xml.internal.ws.fault.ServerSOAPFaultException: Client received SOAP Fault from server: System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object. 
at WebserviceX.Service.Adapter.IPAdapter.CheckIP(String IP) 
at WebserviceX.Service.GeoIPService.GetGeoIP(String IPAddress) 
--- End of inner exception stack trace --- Please see the server log to find more detail regarding exact cause of the failure. 
    at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:178) 
    at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:116) 
    at com.sun.xml.internal.ws.client.sei.StubHandler.readResponse(StubHandler.java:238) 
    at com.sun.xml.internal.ws.db.DatabindingImpl.deserializeResponse(DatabindingImpl.java:189) 
    at com.sun.xml.internal.ws.db.DatabindingImpl.deserializeResponse(DatabindingImpl.java:276) 
    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:104) 
    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:77) 
    at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:147) 
    at com.sun.proxy.$Proxy31.getGeoIP(Unknown Source) 
    at org.manjosh.demo.IPlocationFinder.main(IPlocationFinder.java:19) 

我的代碼:

import net.webservicex.GeoIP; 
import net.webservicex.GeoIPService; 
import net.webservicex.GeoIPServiceSoap; 

public class IPlocationFinder { 

    public static void main(String[] args) { 

     if (args.length != 1){ 
      System.out.println("you need to pass atleast 1 IP address"); 
     } 
     else 
     { 
      String ipAddress = args[0]; 
      GeoIPService ipService = new GeoIPService(); 
      GeoIPServiceSoap geoIpserviceSoap = ipService.getGeoIPServiceSoap(); 
      GeoIP geoIp = geoIpserviceSoap.getGeoIP(ipAddress); 
      System.out.println((String)geoIp.getCountryName()); 
     } 
    } 

} 
+0

試試IP 212.58.246.79看看你是否得到英國。如果這樣做意味着您輸入的IP無法映射。這是一個很糟糕的服務,因爲許多人失蹤。 有數以千計的IP免費數據庫。我發現其中一個,我在自己的MySQL中執行查找,而不是依賴Web服務。 – Arminius

+0

異常說明發生了什麼。你到達了主機,你發送了你的請求,但是這對服務並不好,或者它不對。要進一步挖掘,您需要捕獲您發送的內容以及實際的Soap故障。嘗試使用SOAPUI和tcpMonitor。當您使SOAPUI工作時,您可以比較您的代碼請求和正在運行的SOAPUI請求。 – Vadim

+0

謝謝,它適用於英國。 – manjosh

回答

1

使用的soapUI創建XML和發送請求時,如果你在sopui響應第一。然後檢查您發送的xml請求是否包含所有字段,並在soapui請求中匹配一個。

相關問題