Java android应用程序无法解析主机
我正在用android开发一个应用程序,它连接到wcf服务并返回结果。wcf是用soap编写的,我使用KSOAP2进行连接 起初我连接到一个特定的url,一切都很好。然后我不得不更改url,出现未知异常Java android应用程序无法解析主机,java,android,ksoap2,Java,Android,Ksoap2,我正在用android开发一个应用程序,它连接到wcf服务并返回结果。wcf是用soap编写的,我使用KSOAP2进行连接 起初我连接到一个特定的url,一切都很好。然后我不得不更改url,出现未知异常无法解析主机:没有与名称关联的地址 我已经做了我的研究,解决所有其他类似问题的方法是添加安卓清单互联网连接。但我已经这么做了,有什么建议吗?另一个细节是,使用我的应用程序正常运行的第一个url是一个正常的url,第二个是在本地服务器中,顺便说一句,尽管我的电脑在这个服务器中连接正确。(正确地说,当
无法解析主机:没有与名称关联的地址
我已经做了我的研究,解决所有其他类似问题的方法是添加安卓清单互联网连接。但我已经这么做了,有什么建议吗?另一个细节是,使用我的应用程序正常运行的第一个url是一个正常的url,第二个是在本地服务器中,顺便说一句,尽管我的电脑在这个服务器中连接正确。(正确地说,当我在浏览器中使用url时,与它连接没有问题)
我在这里发布了建立连接的类:
公共类KSoapConnector实现实例化连接{
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>
我知道在安卓系统中,本地主机是10.0.2.2,但我的应用程序将straigth连接到本地服务器……我应该转发任何端口吗?好的,我发现了问题所在。显然,我的应用程序无法解决此url,但这是由于该网站的绑定,因此我将联系管理员。您的SOAP\u操作应该是正确的像这样的
AppConsts.NAMESPACE = "http://www.tempuri.us/"
usecaseString = THIS SHOULD BE YOUR METHOD NAME OF SERVICE.
String soapAction = AppConsts.NAMESPACE + usecaseString;
你的URL应该是这样的
NAMESPACE+/PROJECTNAME/SERVICE_NAME.asmx
你能在具体的代码方面做到吗?你可以使用手机的浏览器连接到url吗?@subirkumarsao我没有尝试过,但它是否相关,因为我可以正确连接到另一个url?@subirkumarsao我尝试过启动我的浏览器,它工作正常。但这仍然没有解决我的问题。正如我之前所说,我怀疑的是我使用的url是本地的,但我不知道这是否真的是一个问题,因为我的电脑浏览器会毫无问题地打开它。。。