import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.OperationClient;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.rpc.client.RPCServiceClient;
//import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
/**
* @program: dfss
* @description:
* @author: jiangkai
* @create: 2021-12-13 16:02
**/
public class TestMain2 {
public static void main(String[] args) throws Exception {
//下面是axis1.4,需要1.4的包
//import org.apache.axis.client.Call;
//import org.apache.axis.client.Service;
//import org.apache.axis.encoding.XMLType;
// String base64Xml = "";
// Service service = new Service();
//
// Call call = (Call) service.createCall();
// call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP12_CONSTANTS);
// call.setTargetEndpointAddress(new java.net.URL("http://192.168.7.16:10000/services/HIPMessageServer?wsdl"));
// call.setOperation("HIPMessageServer");
// call.setUseSOAPAction(true);
// // 设置访问超时
// call.setTimeout(5000);
// call.setSOAPActionURI("urn:hl7-org:v3" + "HIPMessageServer");
// //call.setOperationName(new QName(urlRegister.getDomainName().trim(), urlRegister.getMethodName().trim()));
// //参数设置
// call.addParameter(new QName("urn:hl7-org:v3", "action"), XMLType.XSD_STRING, ParameterMode.IN);
// call.addParameter(new QName("urn:hl7-org:v3", "message"), XMLType.XSD_STRING, ParameterMode.IN);
// //设置返回类型
// call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
//
// String result = (String) call.invoke(new Object[]{"DocumentRegister", base64Xml});
//
// System.out.println("---------------" + result);
}
// axis2方式
private static void axis2WebService01() throws Exception {
try {
String base64Xml = "";
String soapBindingAddress = "http://10.1.170.11:10000/services/HIPMessageServer?wsdl";
ServiceClient sender = new ServiceClient();
EndpointReference endpointReference = new EndpointReference(
soapBindingAddress);
Options options = new Options();
options.setAction("urn:hl7-org:v3HIPMessageServer");
options.setSoapVersionURI(org.apache.axiom.soap.SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
options.setTo(endpointReference);
sender.setOptions(options);
OMFactory fac = OMAbstractFactory.getOMFactory();
// 这个和qname差不多,设置命名空间
OMNamespace omNs = fac.createOMNamespace("urn:hl7-org:v3",
"HIPMessageServer");
OMElement data = fac.createOMElement("HIPMessageServer", omNs);
// 对应参数的节点
String[] strs = new String[]{"action", "message"};
// 参数值
String[] val = new String[]{"DocumentRegister", base64Xml};
for (int i = 0; i < strs.length; i++) {
QName qname = new QName(strs[i]);
OMElement inner = fac.createOMElement(qname);
inner.setText(val[i]);
data.addChild(inner);
}
// 发送数据,返回结果
OMElement result = sender.sendReceive(data);
System.out.println(result.toString());
} catch (AxisFault ex) {
ex.printStackTrace();
}
}
// axis2方式2
private static void axis2WebService02() throws Exception {
String base64Xml = "";
RPCServiceClient client = new RPCServiceClient();
Options options = client.getOptions();
String url = "http://10.1.170.11:10000/services/HIPMessageServer?wsdl";
EndpointReference end = new EndpointReference(url);
// 指定getValue方法返回值的数据类型的Class对象
options.setAction("urn:hl7-org:v3HIPMessageServer");
Class<?>[] classes = new Class[]{String.class};
// 指定要调用的WSDL文件的命名空间及getValue方法
QName qname = new QName("urn:hl7-org:v3", "HIPMessageServer");
options.setTo(end);
// 指定getValue方法的参数值
// Object[] ob = new Object[]{"DocumentRegister", base64Xml};
Object[] ob = new Object[]{"action", "message", "DocumentRegister", base64Xml};
// Object[] ob = new Object[]{base64Xml};
Object result = client.invokeBlocking(qname, ob, classes)[0];
System.out.println("----------------------" + result.toString());
}
}
<!--axis begin-->
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
</dependency>
<!--axis end-->
<!--axis2 begin-->
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-http</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-java2wsdl</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-api</artifactId>
<version>1.2.10</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-impl</artifactId>
<version>1.2.10</version>
</dependency>
<!--axis2 end-->
使用哪一种需要引入对应的包