---
title: "JAVA调用.NET的webservice"
author: "hq369"
date: "2013-07-09T10:04:25Z"
tags: []
categories: ["互联网"]
slug: "java-net-webservice"
draft: false
lastmod: "2013-07-09T10:03:29Z"
id: 1901751
url: "https://hq369.iteye.com/blog/1901751"
---

webservice信息 \[code="java"] POST /upic.asmx HTTP/1.1 Host: u.domain.com Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://tempuri.org/UploadFile" base64Binary string string boolean \[/code] 需要的包：axis.jar,axis-ant.jar,commons-logging-1.1.jar,commons-discovery-0.2.jar,jaxrpc.jar,wsdl4j.jar 代码 \[code="java"] public String getNetService(String fs,String FilePath,String FileName,boolean isCheckFileExist) { try{ String picUrl="http://u.domain.com/upic.asmx"; String SOAPACTION="http://u.domain.com/"; String methodName="UploadFile";//Web 服务提供的方法 Service service = new Service(); Call call = (Call)service.createCall(); call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP12\_CONSTANTS); call.setTargetEndpointAddress(new URL(picUrl)); call.setOperationName(new QName("http://tempuri.org/", methodName)); call.addParameter(new QName("http://tempuri.org/", "fs"),org.apache.axis.encoding.XMLType.XSD\_STRING,javax.xml.rpc.ParameterMode.IN);//定义参数 call.addParameter(new QName("http://tempuri.org/", "FilePath"),org.apache.axis.encoding.XMLType.XSD\_STRING,javax.xml.rpc.ParameterMode.IN); call.addParameter(new QName("http://tempuri.org/", "FileName"),org.apache.axis.encoding.XMLType.XSD\_STRING,javax.xml.rpc.ParameterMode.IN); call.addParameter(new QName("http://tempuri.org/", "isCheckFileExist"),org.apache.axis.encoding.XMLType.XSD\_BOOLEAN,javax.xml.rpc.ParameterMode.IN); call.setReturnType(org.apache.axis.encoding.XMLType.XSD\_STRING); call.setUseSOAPAction(true); call.setSOAPActionURI(SOAPACTION + methodName); String res = (String) call.invoke(new Object\[] { fs, FilePath,FileName, isCheckFileExist});//按定义的顺序给参数传值 return res; }catch (Exception e) { e.printStackTrace(); return "0"; } } \[/code]