JAVA调用C#webservice,返回byte[],写入新文件

来源:互联网 发布:ubuntu启动网络服务 编辑:程序博客网 时间:2024/06/08 01:04

JAVA调用C#webservice,返回byte[],写入新文件

package com.company;import java.io.*;import java.rmi.RemoteException;import java.util.Base64;import javax.xml.namespace.QName;import javax.xml.rpc.ParameterMode;import javax.xml.rpc.ServiceException;import javax.xml.rpc.encoding.XMLType;import org.apache.axis.client.Call;import org.apache.axis.client.Service;public class Main {    public static void main(String[] args) {        String url = "http://localhost:20165/WebsMergeWord.asmx";        String namespace = "http://tempuri.org/";        String methodName = "GetMergeWordByUrl2";        String soapActionURI = "http://tempuri.org/GetMergeWordByUrl2";        Service service = new Service();        Call call;        try {            call = (Call) service.createCall();            call.setTargetEndpointAddress(url);            call.setUseSOAPAction(true);            call.setSOAPActionURI(soapActionURI);            call.setOperationName(new QName(namespace, methodName));            call.addParameter(new QName(namespace, "strWordUrls"), XMLType.XSD_STRING,ParameterMode.IN);            call.setReturnType(XMLType.XSD_STRING);            //设置参数值            StringBuilder sb = new StringBuilder();            sb.append("http://gs.upc.edu.cn/picture/article/33/91/11/f23b8993469d88d2841a697e371e/60c24b95-e043-4454-828a-1c01fdee938c.doc,");            sb.append("http://gs.upc.edu.cn/picture/article/33/91/11/f23b8993469d88d2841a697e371e/60c24b95-e043-4454-828a-1c01fdee938c.doc,");            sb.append("http://gs.upc.edu.cn/picture/article/33/1d/c8/9cc816ad4e9eac16c81fef001b7e/e6a4a998-47a8-4479-91e4-88364dfc5fe3.doc,");            String[] str = new String[1];            str[0] = sb.toString();            Object obj = call.invoke(str);            //解码返回值            byte[] bfile = Base64.getDecoder().decode(obj.toString());            //写入新文件            try{                String path = "C://MergeWordJava//111.doc";                File file = new File(path);                FileOutputStream fos = new FileOutputStream(file);                BufferedOutputStream bos = new BufferedOutputStream(fos);                bos.write(bfile);            }catch (Exception e){                e.printStackTrace();            }        } catch (ServiceException e) {            e.printStackTrace();        } catch (RemoteException e) {            e.printStackTrace();        }    }}



原创粉丝点击