Webservice发布文件下载的服务报错

最近在研究Webservice的文件传输,上网找了很多资料,可都是文件上传的,按理说文件下载的就是文件上传的反向而已,可中间也遇到了问题,当一切都搭好后,消费服务的时候却报错:The server localhost failed to respond,上网查了一下,原来是要[color=red]关闭防火墙和杀毒软件[/color]。ok,一切都解决了。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您可以使用以下步骤在Android中使用WebService下载文件: 1.创建一个类来处理WebService请求 ``` public class WebServiceHandler { private static final String SOAP_ACTION = "http://tempuri.org/DownloadFile"; private static final String METHOD_NAME = "DownloadFile"; private static final String NAMESPACE = "http://tempuri.org/"; private static final String URL = "http://yourwebserviceurl"; public static void downloadFile(String fileName, String fileExtension) { SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); PropertyInfo propertyInfo = new PropertyInfo(); propertyInfo.setName("fileName"); propertyInfo.setValue(fileName); propertyInfo.setType(String.class); request.addProperty(propertyInfo); propertyInfo = new PropertyInfo(); propertyInfo.setName("fileExtension"); propertyInfo.setValue(fileExtension); propertyInfo.setType(String.class); request.addProperty(propertyInfo); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoapObject(request); HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); try { androidHttpTransport.call(SOAP_ACTION, envelope); SoapPrimitive response = (SoapPrimitive) envelope.getResponse(); String fileData = response.toString(); // Save the file FileOutputStream fileOutputStream = new FileOutputStream(Environment.getExternalStorageDirectory() + "/" + fileName + "." + fileExtension); fileOutputStream.write(Base64.decode(fileData, Base64.NO_WRAP)); fileOutputStream.close(); } catch (Exception e) { e.printStackTrace(); } } } ``` 2.在Android应用程序中调用该方法 ``` WebServiceHandler.downloadFile("samplefile", "txt"); ``` 这将下载名为“samplefile.txt”的文件,并保存在设备的根目录中。 请注意,您需要替换“SOAP_ACTION”,“METHOD_NAME”,“NAMESPACE”和“URL”与您自己的WebService URL。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值