Android应用程序使用kso​​ap2在GlassFish服务器上使用WebService

时间:2014-03-24 16:37:06

标签: java android web-services glassfish

我有一个Android应用程序,它使用位于笔记本电脑上的GlassFish服务器上的Web服务。当我的笔记本电脑和我的设备都连接到WiFi时,它按预期工作。但是当我的设备连接到移动3G网络时,当我尝试访问web服务时,它会抛出超时错误:

  

W / System.err(3835):java.net.ConnectException:无法连接到> / [RouterIPAddress](端口8080):连接失败:ETIMEDOUT(连接超时)

我已将路由器配置为将HTTP转发到我的笔记本电脑IP和端口8080。

这是我调用WebService的代码:

public class WebService {
//Namespace of the Webservice - can be found in WSDL
private static String NAMESPACE = "http://service.marcusjacobsson.com/";
//Webservice URL - WSDL File location    
private static String URL = "http://[myRoutersIPAddress]:8080/WebServiceProject/HelloWebService?wsdl";
//SOAP Action URI again Namespace + Web method name
private static String SOAP_ACTION = "http://service.marcusjacobsson.com/";

public static String[] invokeHelloWorldWS(String webMethName) {
    String[] resultArray = null;
    // Create request
    SoapObject request = new SoapObject(NAMESPACE, webMethName);       
    // Create envelope
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
            SoapEnvelope.VER11);
    // Set output SOAP object
    envelope.setOutputSoapObject(request);
    // Create HTTP call object
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

    try {
        // Invoke web service
        androidHttpTransport.call(SOAP_ACTION+webMethName, envelope);
        // Get the response
        SoapObject response = (SoapObject) envelope.bodyIn;

        if(response!=null){
            int count = response.getPropertyCount();
            resultArray = new String[count];
            for(int i=0;i<count;i++){
                resultArray[i]=response.getProperty(i).toString();
            }
        }
        return resultArray;

    } catch (Exception e) {
        //Print error
        e.printStackTrace();
    } 
    //Return resTxt to calling object
    return resultArray;
}   

}

导致应用程序无法通过移动互联网连接到我的笔记本电脑的原因是什么,但当两台设备在同一个wifi上运行时它可以正常工作? (IP地址需要一些配置)

提前感谢您提供有关如何调试此问题的任何答案或提示。

0 个答案:

没有答案