android应用程序无法解析主机

问题描述:

我正在开发一个应用程序,它连接到一个wcf服务并返回结果。wcf是用soap编写的,我使用KSOAP2进行连接。android应用程序无法解析主机

起初我连接到一个特定的网址,一切都很好。然后我不得不改变网址,我得到一个未知的例外unable to resolve host:No address associated with name

我已经完成了我的研究,解决所有其他类似问题的方法是在Android Manifest互联网连接中添加。但我已经做到了。有什么建议吗?另一个细节是,使用第一个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(); 
    } 

}

和这里是我的manifet文件:

<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的本地主机是10.0.2.2,但我的应用程序连接straigth到本地服务器......我应该转发任何端口?

+0

你能明确的代码明智吗? – Michal 2012-07-16 07:41:07

+0

您可以使用手机的浏览器连接到网址? – 2012-07-16 07:44:07

+0

@subirkumarsao我还没有尝试过,但它是相关的,因为我能够正确连接与其他网址? – Libathos 2012-07-16 07:51:04

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

您的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