在java中为Android应用程序使用带有ksoap2的.asmx服务时出现IOException [英] IOException while using .asmx service with ksoap2 in java for android app

查看:62
本文介绍了在java中为Android应用程序使用带有ksoap2的.asmx服务时出现IOException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的专业人士,



我使用kso​​ap2类在Android应用程序中调用asp.net Web服务方法,该应用程序由本网站的示例引导。我得到一个java.net套接字超时异常。



请帮我弄清代码中的错误。



我试过的:



我添加了< uses-permission android:name =android.permission.INTERNETxmlns:android =#unknown>在清单中,还在构建路径等中添加了库引用,



我确保ASP.net webservice能够很好地从其他.net应用程序和探险家。



我在网上搜索了几个解决方案。但没找到一个解决我的问题或者可能不是我的理解。





请注意:我参与过SOAP与android在早期项目中使用kso​​ap2并通过。这次我错过了什么。请帮忙。



提前致谢。



Dear Professionals,

Im using ksoap2 classes for invoking asp.net Web service methods in an android application guided by examples from this site. I am getting a java.net socket timed out exception.

Kindly help me figure out mistake in the code.

What I have tried :

I have added <uses-permission android:name="android.permission.INTERNET" xmlns:android="#unknown"> in the manifest and also added the library ref in the Build path etc.,

I have ensured the ASP.net webservice works well from other .net apps and from the explorer.

I have googled for several solutions online. But didn't find one to solve my issue or may be not to my understanding.


Please Note : I have worked on SOAP with android using ksoap2 in earlier projects and was through. This time I'm missing something. Please help.

Thanks in advance.

package com.Test.testtvgrm;

import java.io.IOException;

import org.apache.http.client.HttpResponseException;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

public class TestWS 
{
    public String SoapAction = "http://192.168.5.28/GetFolio";
    public String WSDLTargetNameSpace = "http://192.168.5.28/";
    public String SoapAddress = "http://192.168.5.28/grmserver/service.asmx";
	
    public TestWS()
    {

    }  
    
    public String CallFunc(int mfunc,String mpara)
    {
    	Object response = null;		
	SoapObject sorequest = new SoapObject(WSDLTargetNameSpace, "GetFolio");	  
    	String[] mparavalues = mpara.split("%");
	if (mfunc == 1)
	{
	    sorequest.addProperty("mpath", mparavalues[1]);
	    sorequest.addProperty("mroomno",mparavalues[2]);
	}    	
	SoapSerializationEnvelope soenvelope = new SoapSerializationEnvelope
        (SoapEnvelope.VER11);
	soenvelope.dotNet = true;
	soenvelope.setOutputSoapObject(sorequest);    	
	HttpTransportSE httpTransport = new HttpTransportSE(SoapAddress);
	httpTransport.debug=true;
	try
	{
	    httpTransport.call(SoapAction, soenvelope);
	    response = soenvelope.getResponse();
	}
	catch (HttpResponseException e) 
	{             
            e.printStackTrace();
	} 
	catch (IOException e) 
	{               
            e.printStackTrace();
	} 
        catch (XmlPullParserException e) 
        {                
            e.printStackTrace();
	}       
    	return response.toString();
    }
}





我从另一个调用后台方法的类调用'CallFunc'方法做任务。该代码如下:





I'm calling the 'CallFunc' method from another class which invokes a background method to do the task. That code is as below :

Task_GetFolio = new GetFolio();
Task_GetFolio.execute((Void) null);





后台任务在这堂课:





The background task is in this class :

public class GetFolio extends AsyncTask<Void, Void, Boolean>
{
@Override
protected Boolean doInBackground(Void... params)
{
    try
    {
    TestWS mobj = new TestWS();
    String mret = mobj.CallFunc(1, "%c:\\%1%");
    FolioFetched=true;
    }
    catch (Exception e1)
    {
    FolioFetched=false;
    }
    return FolioFetched;
}

    @Override
protected void onPostExecute(final Boolean success)
{
    Task_GetFolio=null;
    finish();
}

@Override
protected void onCancelled()
    {
    Task_GetFolio=null;
    finish();
}
}

推荐答案

本地防火墙就是问题所在。我允许在防火墙高级设置中使用万维网服务(HTTP),这解决了我的问题。
Local Firewall was the issue. I allowed World Wide Web Services (HTTP) in the firewall advanced settings which solved the problem for me.


这篇关于在java中为Android应用程序使用带有ksoap2的.asmx服务时出现IOException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆