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());
}
}
}
试试IP 212.58.246.79看看你是否得到英国。如果这样做意味着您输入的IP无法映射。这是一个很糟糕的服务,因为许多人失踪。 有数以千计的IP免费数据库。我发现其中一个,我在自己的MySQL中执行查找,而不是依赖Web服务。 – Arminius
异常说明发生了什么。你到达了主机,你发送了你的请求,但是这对服务并不好,或者它不对。要进一步挖掘,您需要捕获您发送的内容以及实际的Soap故障。尝试使用SOAPUI和tcpMonitor。当您使SOAPUI工作时,您可以比较您的代码请求和正在运行的SOAPUI请求。 – Vadim
谢谢,它适用于英国。 – manjosh