我正在android中开发一个连接到wcf服务并返回结果的应用程序。wcf是用soap编写的,我正在使用KSOAP2进行连接。
起初我连接到某个 url,一切运行良好。然后我不得不更改 url,我得到一个未知的异常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 但我的应用程序直接连接到本地服务器......我应该转发任何端口吗?