我正在開發一個應用程序,它連接到一個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到本地服務器......我應該轉發任何端口?
你能明確的代碼明智嗎? – Michal 2012-07-16 07:41:07
您可以使用手機的瀏覽器連接到網址? – 2012-07-16 07:44:07
@subirkumarsao我還沒有嘗試過,但它是相關的,因爲我能夠正確連接與其他網址? – Libathos 2012-07-16 07:51:04