axis2调用webservice报错System.Web.Services.Protocols.SoapException: Server did not recognize

具体报错信息

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;
    }
}

至此,webservice接通调通!但是出现新错误,value cannot be  null,解决办法见下篇。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值