Axis调用webservice
import com.google.gson.Gson;
import org.apache.axis.client.Call;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.Map;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
public class SoapUtils {
private static Logger logger = LoggerFactory.getLogger(PostJsonUtil.class);
public Map<String,Object> map = new HashMap<String,Object>();
public static String doSoap(String invokUrl, ConditonDto conditonDto) {
//拼接参数
String method = "pushWbData";
String soapResponseData = "";
StringBuffer stringBuffer = new StringBuffer();
Gson gson = new Gson();
String sttr = gson.toJson(conditonDto);
/*WbHlwWebservice wbHlwWebservice= new WbHlwWebservice();
com.t3.ts.guangzhou.standard.data.webservice.WbHlwWebservicePortType WbHlwWebservicePortType =wbHlwWebservice.getWbHlwWebserviceHttpPort();
String rest =WbHlwWebservicePortType.pushWbData(sttr);
return "0";//rest;*/
String result = "";
Service service = new Service();
try {
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(invokUrl);
call.setEncodingStyle("utf-8");
call.addParameter("condition", org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
call.setOperationName(new QName(invokUrl,method));
result = (String) call.invoke(new Object[]{sttr});
System.out.println("返回值:" + result);
} catch (Exception e) {
System.out.print("WebService请求异常!! ");
e.printStackTrace();
}
return result;
}
}
pom依赖
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-discovery</groupId>
<artifactId>commons-discovery</artifactId>
<version>0.2</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis-jaxrpc</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis-saaj</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.4</version>
</dependency>
注意:url地址后面?wsdl去掉