java 调用webservice sopui解析出来方法都带前缀无法正常调用

网上的wsdl 说明示例:

有个项目上遇到解析出来都是带有前缀的,例如:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.founder.com">
   <soapenv:Header/>
   <soapenv:Body>
      <ser:funInterFaceMZBYJ>
         <ser:in0>?</ser:in0>
      </ser:funInterFaceMZBYJ>
   </soapenv:Body>
</soapenv:Envelope>
View Code

之前一直用的hutool 调用 webservice,都比较好用,但是遇到这种奇怪的格式就一直报命名空间的错误。只有换种方式,网上搜了下,亲测可用。参考地址:(20条消息) Java调用WebService的几种方式_世界joker的博客-CSDN博客_java webservice

具体步骤如下

1、引用包

<!--spring web Service的包-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
            <version>1.5.2.RELEASE</version>
        </dependency>

        <!--spring web service wsdl包-->
        <dependency>
            <groupId>wsdl4j</groupId>
            <artifactId>wsdl4j</artifactId>
            <version>1.6.3</version>
        </dependency>
        <!-- axis 1.4 jar start -->
        <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>

 

2、执行示例

 //wsdl地址
        String endpoint ="http://100.100.100.63:8888/founderWebs/services/ICalculateServicePZH";
        //命名空间
        String namespace = "http://www.w3.org/2001/XMLSchema";
        //服务名
        String serviceName = "ICalculateServicePZH";
        //方法名
        String methodName = "funInterFaceMZBYJ";
        //soapAction
        String soapAction = "";


        Service service = new Service();
        Call call = (Call) service.createCall();
        //设置响应超时
        call.setTimeout(3000);

        //设置地址
        call.setTargetEndpointAddress(endpoint);

        //设置方法名
        call.setOperationName(new QName(namespace,methodName));

        String param = "<funderService functionName='MZBYJ_201'>" +
                "              <value>1</value>" +
                "   <value>"+code+"</value>   " +
                "  </funderService>";
        //设置参数
        call.addParameter("Message", XMLType.XSD_STRING, ParameterMode.IN);
        String message = param;
        Object [] obj = {message};

        //设置返回类型
        call.setReturnType(XMLType.XSD_STRING);

        //启用soap
        call.setUseSOAPAction(true);
        //设置soapAction
        call.setSOAPActionURI(soapAction);

        //设置服务名
        SOAPService soapService = new SOAPService();
        soapService.setName(serviceName);
        call.setSOAPService(soapService);
        String ret = (String) call.invoke(obj);
View Code

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章