具体报错信息
System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: urn:anonOutInOp.
解决此报错关键代码
options.setAction(targetNamespace + "/" + opName);
解决问题后代码:
package com.cpinfo.his.web.order;
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.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.databinding.utils.BeanUtil;
import org.apache.axis2.engine.DefaultObjectSupplier;
import org.apache.axis2.rpc.client.RPCServiceClient;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.endpoint.dynamic.DynamicClientFactory;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import java.io.StringReader;
public class FcPublicHealthUtil {
public static RPCServiceClient rpcServiceClient = null;
public static Options options = null;
static {
try {
rpcServiceClient = new RPCServiceClient();
options = rpcServiceClient.getOptions();
} catch (Exception e) {
e.printStackTrace();
}
}
public static String getService(String serviceUrl) throws Exception {
String result = "";
String reqXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><AccountReq><SystemType>1</SystemType><HospitalCode>T370983104001</HospitalCode><HospitalLicense>1e65e7a5e21043f6887ec069fbaa983a</HospitalLicense><HospitalName>王庄卫生院</HospitalName><BusinessCode>70005</BusinessCode><UserName>王伟1</UserName><Pwd>5500</Pwd></AccountReq>";
Object[] opArgs = new Object[]{ reqXML };
Class[] opReturnType = new Class[] { String.class };
String targetNamespace = "http://tempuri.org/";
String opName = "Do_Transaction";
QName opQName = new QName(targetNamespace, opName);
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
EndpointReference targetEPR = new EndpointReference(serviceUrl);
options.setTo(targetEPR);
options.setAction(targetNamespace + "/" + opName);
Object[] ome = serviceClient.invokeBlocking(opQName, opArgs, opReturnType);
result = (String)ome[0];
return result;
}
public static Element readXmlRoot(String xmlStr) throws Exception {
SAXBuilder saxBuilder = new SAXBuilder();
org.jdom.Document doc = saxBuilder.build(new StringReader(xmlStr));
org.jdom.Element root = doc.getRootElement();
return root;
}
}