android app无法解析主机

时间:2012-07-16 07:36:40

标签: java android ksoap2

我正在android中开发一个连接到wcf服务并返回结果的应用程序.wcf是用soap编写的,我使用KSOAP2进行连接。

起初我连接到某个网址,一切都很顺利。然后我不得不更改网址,我得到一个未知的异常unable to resolve host:No address associated with name

我已经完成了我的研究,所有其他类似问题的解决方案是添加Android Manifest互联网连接。但我已经这样做了。有什么建议吗?另一个细节是使用第一个url,我的应用程序工作正常,是一个普通的url,第二个是在本地服务器,顺便说一下,虽然我的电脑正确连接在这个服务器。(正确的意思是当我使用使用我的浏览器的url连接它没有问题)

我在这里发布了建立连接的类:

公共类KSoapConnector实现InstantiateConnection {

private SoapObject response;
private WcfReceivedClass identifier;
private WcfReceivedClass[] receivedData;    
private final String NAMESPACE = "http://microsoft.com/webservices/";
private String METHOD_NAME="GetTeacherClass";         
private String SOAP_ACTION = "http://microsoft.com/webservices/IVertiSchool_SRV/GetTeacherClass";
private final String URL = "http://vertiserv1:81/VertiSchool_SRV.svc";

    //below is the url which was working fine
//private final String URL = "http://wcf.schoolportal.gr/VertiSchool_SRV.SVC";



public  KSoapConnector(String methodName,int mode){





    SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);

    //here are the parameters for the wcf service and there values are correctly put   
    Request.addProperty("connString", "connectionString");
    Request.addProperty("TeCode", "tCode");
    Request.addProperty("Company", "cmp");
    Request.addProperty("Lng", "lng");
    Request.addProperty("MainPeriod", "mainPrd");


    SoapSerializationEnvelope envelope = new SerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(Request);      
envelope.addMapping(NAMESPACE, "SRV_Class",new SRV_Class().getClass());
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);


    try{

        //here is where i get the exception...
        androidHttpTransport.call(SOAP_ACTION, envelope);

        response = (SoapObject)envelope.getResponse();

        receivedData = identifier.retrieveFromSoap(response);
    }
    catch(Exception e){
        e.printStackTrace();
    }

}

这是我的文件:

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.example.myapp"
     android:versionCode="1"
     android:versionName="1.0" >

        <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />  

 <uses-sdk android:minSdkVersion="7" /> 

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>        
    <activity android:name=".ListOfClasses"></activity>            
</application>

我知道在Android中localhost是10.0.2.2,但是我的应用程序将straigth连接到本地服务器......我应该转发任何端口吗?

2 个答案:

答案 0 :(得分:0)

你的SOAP_ACTION应该是这样的。

AppConsts.NAMESPACE =  "http://www.tempuri.us/"

usecaseString = THIS SHOULD BE YOUR METHOD NAME OF SERVICE.

String soapAction = AppConsts.NAMESPACE + usecaseString;

你的网址应该是这样的。

NAMESPACE+/PROJECTNAME/SERVICE_NAME.asmx

答案 1 :(得分:-1)

好吧我发现了什么问题。显然这个网址无法通过我的应用程序解决,但这是由于该网站的绑定所以我将联系管理员。