简体   繁体   English

Android应用无法解析主机

[英]android app cannot resolve host

I'm developing an application in android which connects to a wcf service and returns the results.The wcf is written with soap and I'm using KSOAP2 for connecting. 我正在用android开发一个应用程序,该应用程序连接到wcf服务并返回结果。wcf用soap编写,并且我使用KSOAP2进行连接。

At first I was connecting to a certain url and everything was working nicely. 最初,我连接到某个URL,并且一切正常。 Then I had to change the url and I get an unknown exception unable to resolve host:No address associated with name . 然后,我不得不更改url,并且得到了一个未知的异常, unable to resolve host:No address associated with name

I've done my research and the solution to all the other similar problems was adding in the Android Manifest internet connection. 我已经进行了研究,所有其他类似问题的解决方案都是在Android Manifest网络连接中添加。 But I've done that already .Any suggestions? 但是我已经做到了。有什么建议吗? Another detail is that using the first url ,in which my application was working fine, is a normal url the second is in a local server ,by the way though my pc is connected properly in this server.(properly meaning that when i use the url with my browser has no problem connecting with it ) 另一个细节是,尽管我的PC已正确连接到该服务器,但使用我的应用程序正常运行的第一个url是普通的URL,第二个位于本地服务器中,这是我的PC已正确连接的方式。我的浏览器的url与它连接没有问题)

I'm posting here the class which establishes the connection: 我在这里发布建立连接的类:

public class KSoapConnector implements InstantiateConnection{ 公共类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();
    }

} }

and here is my manifet file : 这是我的清单文件:

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

I know that in Android the localhost is 10.0.2.2 but my application connects straigth to the local server...should i forward any ports? 我知道在Android中,本地主机是10.0.2.2,但是我的应用程序将straigth连接到本地服务器...我应该转发任何端口吗?

Your SOAP_ACTION should be something like this. 您的SOAP_ACTION应该是这样的。

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

usecaseString = THIS SHOULD BE YOUR METHOD NAME OF SERVICE.

String soapAction = AppConsts.NAMESPACE + usecaseString;

And your URL should be something like this. 您的网址应该是这样的。

NAMESPACE+/PROJECTNAME/SERVICE_NAME.asmx

好的,我发现了问题所在。显然,该网址无法由我的应用程序解析,但这是由于该网站的绑定所致,所以我将与管理员联系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM