SpringBoot整合webService类参数方式调用

所需wsdl文件

https://download.csdn.net/download/weixin_45534157/86937310

根据wsdl文件生成服务端、客户端代码

SpringBoot整合webService类参数方式调用_第1张图片
SpringBoot整合webService类参数方式调用_第2张图片

实体类添加注解

需要在生成的实体类添加对应注解@XmlAccessorType(XmlAccessType.FIELD)、@XmlType、@XmlElement
InputParameters

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(
        name = "InputParameters",
        propOrder = {"MSGHEADER", "MD_CODE", "VENDOR_NAME", "ORGCERT_NUMBER", "IDENTIFY_CODE", "SOC_IDEN", "VENDOR_STATUS", "CREATION_DATE", "OU_CODE", "QUERY_EXT", "LAST_UPDATE_START", "LAST_UPDATE_END"}
)
public class InputParameters  implements java.io.Serializable {
    @XmlElement(
            name = "MSGHEADER",
            required = true
    )
    protected com.cmcc.soa.OSB_BP_MDM_HQ_PageInquiryVendorSrv.MSGHEADER MSGHEADER;
    @XmlElement(
            name = "MD_CODE",
            required = true,
            nillable = true
    )
    protected java.lang.String MD_CODE;
    @XmlElement(
            name = "VENDOR_NAME",
            required = true,
            nillable = true
    )
    protected java.lang.String VENDOR_NAME;
    @XmlElement(
            name = "ORGCERT_NUMBER",
            required = true,
            nillable = true
    )
    protected java.lang.String ORGCERT_NUMBER;
    @XmlElement(
            name = "IDENTIFY_CODE",
            required = true,
            nillable = true
    )
    protected java.lang.String IDENTIFY_CODE;
    @XmlElement(
            name = "SOC_IDEN",
            required = true,
            nillable = true
    )
    protected java.lang.String SOC_IDEN;
    @XmlElement(
            name = "VENDOR_STATUS",
            required = true,
            nillable = true
    )
    protected java.lang.String VENDOR_STATUS;
    @XmlElement(
            name = "CREATION_DATE",
            required = true,
            nillable = true
    )
    protected java.util.Calendar CREATION_DATE;
    @XmlElement(
            name = "OU_CODE",
            required = true,
            nillable = true
    )
    protected java.lang.String OU_CODE;
    @XmlElement(
            name = "QUERY_EXT",
            required = true,
            nillable = true
    )
    protected java.lang.String QUERY_EXT;
    @XmlElement(
            name = "LAST_UPDATE_START",
            required = true,
            nillable = true
    )
    protected java.util.Calendar LAST_UPDATE_START;
    @XmlElement(
            name = "LAST_UPDATE_END",
            required = true,
            nillable = true
    )
    protected java.util.Calendar LAST_UPDATE_END;

MSGHEADER
SpringBoot整合webService类参数方式调用_第3张图片
命名空间取wsdl上面

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(
        name = "MSGHEADER",
        namespace = "http://soa.cmcc.com/MsgHeader",
        propOrder = {"SOURCESYSTEMID", "SOURCESYSTEMNAME","TOKEN", "USER_ID", "USER_NAME", "USER_PASSWD", "SUBMIT_DATE","PAGE_SIZE", "CURRENT_PAGE", "TOTAL_RECORD", "PROVINCE_CODE","ROUTE_CODE","TRACE_ID","RESERVED_1","RESERVED_2"}
)
public class MSGHEADER  implements java.io.Serializable {
    @XmlElement(
            name = "SOURCESYSTEMID",
            required = true,
            nillable = true
    )
    protected java.lang.String SOURCESYSTEMID;
    @XmlElement(
            name = "SOURCESYSTEMNAME",
            required = true,
            nillable = true
    )
    protected java.lang.String SOURCESYSTEMNAME;
    @XmlElement(
            name = "TOKEN",
            required = true,
            nillable = true
    )
    protected java.lang.String TOKEN;
    @XmlElement(
            name = "USER_ID",
            required = true,
            nillable = true
    )
    protected java.math.BigDecimal USER_ID;
    @XmlElement(
            name = "USER_NAME",
            required = true,
            nillable = true
    )
    protected java.lang.String USER_NAME;
    @XmlElement(
            name = "USER_PASSWD",
            required = true,
            nillable = true
    )
    protected java.lang.String USER_PASSWD;
    @XmlElement(
            name = "SUBMIT_DATE",
            required = true,
            nillable = true
    )
    protected java.util.Calendar SUBMIT_DATE;
    @XmlElement(
            name = "PAGE_SIZE",
            required = true,
            nillable = true
    )
    protected java.math.BigDecimal PAGE_SIZE;
    @XmlElement(
            name = "CURRENT_PAGE",
            required = true,
            nillable = true
    )
    protected java.math.BigDecimal CURRENT_PAGE;
    @XmlElement(
            name = "TOTAL_RECORD",
            required = true,
            nillable = true
    )
    protected java.math.BigDecimal TOTAL_RECORD;
    @XmlElement(
            name = "PROVINCE_CODE",
            required = true,
            nillable = true
    )
    protected java.lang.String PROVINCE_CODE;
    @XmlElement(
            name = "ROUTE_CODE",
            required = true,
            nillable = true
    )
    protected java.lang.String ROUTE_CODE;
    @XmlElement(
            name = "TRACE_ID",
            required = true,
            nillable = true
    )
    protected java.lang.String TRACE_ID;
    @XmlElement(
            name = "RESERVED_1",
            required = true,
            nillable = true
    )
    protected java.lang.String RESERVED_1;
    @XmlElement(
            name = "RESERVED_2",
            required = true,
            nillable = true
    )
    protected java.lang.String RESERVED_2;

OutputParameters

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(
        name = "OutputParameters",
        propOrder = {"ESB_FLAG", "ESB_RETURN_CODE", "ESB_RETURN_MESSAGE", "BIZ_SERVICE_FLAG", "BIZ_RETURN_CODE", "BIZ_RETURN_MESSAGE",
                "INSTANCE_ID", "TOTAL_RECORD","TOTAL_PAGE","PAGE_SIZE","CURRENT_PAGE","OUTPUTCOLLECTION"}
)
public class OutputParameters  implements java.io.Serializable {
    @XmlElement(
            name = "ESB_FLAG",
            required = true,
            nillable = true
    )
    private java.lang.String ESB_FLAG;
    @XmlElement(
            name = "ESB_RETURN_CODE",
            required = true,
            nillable = true
    )
    private java.lang.String ESB_RETURN_CODE;
    @XmlElement(
            name = "ESB_RETURN_MESSAGE",
            required = true,
            nillable = true
    )
    private java.lang.String ESB_RETURN_MESSAGE;
    @XmlElement(
            name = "BIZ_SERVICE_FLAG",
            required = true,
            nillable = true
    )
    private java.lang.String BIZ_SERVICE_FLAG;
    @XmlElement(
            name = "BIZ_RETURN_CODE",
            required = true,
            nillable = true
    )
    private java.lang.String BIZ_RETURN_CODE;
    @XmlElement(
            name = "BIZ_RETURN_MESSAGE",
            required = true,
            nillable = true
    )
    private java.lang.String BIZ_RETURN_MESSAGE;
    @XmlElement(
            name = "INSTANCE_ID",
            required = true,
            nillable = true
    )
    private java.lang.String INSTANCE_ID;
    @XmlElement(
            name = "TOTAL_RECORD",
            required = true,
            nillable = true
    )
    private java.math.BigDecimal TOTAL_RECORD;
    @XmlElement(
            name = "TOTAL_PAGE",
            required = true,
            nillable = true
    )
    private java.math.BigDecimal TOTAL_PAGE;
    @XmlElement(
            name = "PAGE_SIZE",
            required = true,
            nillable = true
    )
    private java.math.BigDecimal PAGE_SIZE;
    @XmlElement(
            name = "CURRENT_PAGE",
            required = true,
            nillable = true
    )
    private java.math.BigDecimal CURRENT_PAGE;
    @XmlElement(
            name = "OUTPUTCOLLECTION",
            required = true,
            nillable = true
    )
    private com.cmcc.soa.OSB_BP_MDM_HQ_PageInquiryVendorSrv.OUTPUTCOLLECTION_ITEM[] OUTPUTCOLLECTION;

其他的对象实体类都需要添加对应注解,一级get/set方法

更改service接口

添加注解@WebService、@SOAPBinding、@WebMethod、@WebResult、@WebParam

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;

@WebService(name = "OSB_BP_MDM_HQ_PageInquiryVendorSrv",// 暴露服务名称
        targetNamespace = "http://soa.cmcc.com/OSB_BP_MDM_HQ_PageInquiryVendorSrv")// 命名空间,一般是接口的包名倒序
@SOAPBinding(
        parameterStyle = SOAPBinding.ParameterStyle.BARE
)
public interface OSB_BP_MDM_HQ_PageInquiryVendorSrv_PortType extends java.rmi.Remote {

    @WebMethod(action = "process")//接口方法
    @WebResult(name = "OutputParameters",targetNamespace = "http://soa.cmcc.com/OSB_BP_MDM_HQ_PageInquiryVendorSrv",partName = "payload")//接口返回值
    public com.cmcc.soa.OSB_BP_MDM_HQ_PageInquiryVendorSrv.OutputParameters process(@WebParam(name = "InputParameters",targetNamespace = "http://soa.cmcc.com/OSB_BP_MDM_HQ_PageInquiryVendorSrv",partName = "payload")com.cmcc.soa.OSB_BP_MDM_HQ_PageInquiryVendorSrv.InputParameters payload) throws java.rmi.RemoteException;
}

更改接口实现类

添加注解@WebService、@SOAPBinding、@WebParam

import org.springframework.stereotype.Component;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;

@Component
@WebService(serviceName = "OSB_BP_MDM_HQ_PageInquiryVendorSrv",// 与接口中指定的name一致
        targetNamespace = "http://soa.cmcc.com/OSB_BP_MDM_HQ_PageInquiryVendorSrv",// 与接口中指定的name一致
        endpointInterface = "com.cmcc.soa.OSB_BP_MDM_HQ_PageInquiryVendorSrv.OSB_BP_MDM_HQ_PageInquiryVendorSrv_PortType")// 接口地址
@SOAPBinding(
        parameterStyle = SOAPBinding.ParameterStyle.BARE
)
public class OSB_BP_MDM_HQ_PageInquiryVendorSrvBindingImpl implements com.cmcc.soa.OSB_BP_MDM_HQ_PageInquiryVendorSrv.OSB_BP_MDM_HQ_PageInquiryVendorSrv_PortType{

    public com.cmcc.soa.OSB_BP_MDM_HQ_PageInquiryVendorSrv.OutputParameters process(@WebParam(name = "InputParameters",targetNamespace = "http://soa.cmcc.com/OSB_BP_MDM_HQ_PageInquiryVendorSrv",partName = "payload") com.cmcc.soa.OSB_BP_MDM_HQ_PageInquiryVendorSrv.InputParameters payload) throws java.rmi.RemoteException {
        OutputParameters outputParameters = new OutputParameters();
        return outputParameters;
    }

}

发布服务

import com.test.test_web.server.MyWebService;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;

@Configuration
public class WebServiceConfig {

    @Bean
    public ServletRegistrationBean disServlet(){
        return new ServletRegistrationBean(new CXFServlet(),"/webService/*");
    }

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }

    /**
     *
     * @return
     */
    @Bean
    public Endpoint endpoint(com.cmcc.soa.OSB_BP_MDM_HQ_PageInquiryVendorSrv.OSB_BP_MDM_HQ_PageInquiryVendorSrv_PortType osb_bp_mdm_hq_pageInquiryVendorSrv_portType) {
        EndpointImpl endpoint = new EndpointImpl(springBus(), osb_bp_mdm_hq_pageInquiryVendorSrv_portType);
        endpoint.publish("/OSB_BP_MDM_HQ_PageInquiryVendorSrv");
        return endpoint;
    }

   /**
     * 多个服务用到
     * @return
     */
/**    @Bean
    public Endpoint endpoint1(MyWebService myWebService) {
        EndpointImpl endpoint = new EndpointImpl(springBus(), myWebService);
        endpoint.publish("/myWebService");
        return endpoint;
    }*/

}

调用方法

添加代理类

public class OSB_BP_MDM_HQ_PageInquiryVendorSrvProxy implements OSB_BP_MDM_HQ_PageInquiryVendorSrv_PortType {
  private String _endpoint = null;
  private OSB_BP_MDM_HQ_PageInquiryVendorSrv_PortType oSB_BP_MDM_HQ_PageInquiryVendorSrv_PortType = null;

  public OSB_BP_MDM_HQ_PageInquiryVendorSrvProxy() {
    _initOSB_BP_MDM_HQ_PageInquiryVendorSrvProxy();
  }
  
  public OSB_BP_MDM_HQ_PageInquiryVendorSrvProxy(String endpoint) {
    _endpoint = endpoint;
    _initOSB_BP_MDM_HQ_PageInquiryVendorSrvProxy();
  }
  
  private void _initOSB_BP_MDM_HQ_PageInquiryVendorSrvProxy() {
    try {
      oSB_BP_MDM_HQ_PageInquiryVendorSrv_PortType = (new OSB_BP_MDM_HQ_PageInquiryVendorSrv_ServiceLocator()).getOSB_BP_MDM_HQ_PageInquiryVendorSrvPort();
      if (oSB_BP_MDM_HQ_PageInquiryVendorSrv_PortType != null) {
        if (_endpoint != null)
          ((javax.xml.rpc.Stub)oSB_BP_MDM_HQ_PageInquiryVendorSrv_PortType)._setProperty("javax.xml.rpc.service.endpoint.address", _endpoint);
        else
          _endpoint = (String)((javax.xml.rpc.Stub)oSB_BP_MDM_HQ_PageInquiryVendorSrv_PortType)._getProperty("javax.xml.rpc.service.endpoint.address");
      }
      
    }
    catch (javax.xml.rpc.ServiceException serviceException) {}
  }
  
  public String getEndpoint() {
    return _endpoint;
  }
  
  public void setEndpoint(String endpoint) {
    _endpoint = endpoint;
    if (oSB_BP_MDM_HQ_PageInquiryVendorSrv_PortType != null)
      ((javax.xml.rpc.Stub)oSB_BP_MDM_HQ_PageInquiryVendorSrv_PortType)._setProperty("javax.xml.rpc.service.endpoint.address", _endpoint);
    
  }
  
  public OSB_BP_MDM_HQ_PageInquiryVendorSrv_PortType getOSB_BP_MDM_HQ_PageInquiryVendorSrv_PortType() {
    if (oSB_BP_MDM_HQ_PageInquiryVendorSrv_PortType == null)
      _initOSB_BP_MDM_HQ_PageInquiryVendorSrvProxy();
    return oSB_BP_MDM_HQ_PageInquiryVendorSrv_PortType;
  }
  
  public OutputParameters process(InputParameters payload) throws java.rmi.RemoteException{
    if (oSB_BP_MDM_HQ_PageInquiryVendorSrv_PortType == null)
      _initOSB_BP_MDM_HQ_PageInquiryVendorSrvProxy();
    return oSB_BP_MDM_HQ_PageInquiryVendorSrv_PortType.process(payload);
  }
  
}

测试

    @RequestMapping("/test")
    public String OSB_BP_MDM_HQ_PageInquiryVendorSrvProxy(){
        String url = "http://192.168.32.131:8010/webService/OSB_BP_MDM_HQ_PageInquiryVendorSrv?wsdl";
        OSB_BP_MDM_HQ_PageInquiryVendorSrvProxy osb_bp_mdm_hq_pageInquiryVendorSrvProxy = new OSB_BP_MDM_HQ_PageInquiryVendorSrvProxy(url);
        InputParameters req = new InputParameters();
        MSGHEADER msgHeader = new MSGHEADER();
        msgHeader.setSOURCESYSTEMID("1");
        msgHeader.setSOURCESYSTEMNAME("1");
        msgHeader.setTOKEN("rrr");
        msgHeader.setUSER_ID(new BigDecimal("1"));
        msgHeader.setUSER_NAME("1");
        msgHeader.setPAGE_SIZE(new BigDecimal(100));
        msgHeader.setCURRENT_PAGE(new BigDecimal(1));
        msgHeader.setTOTAL_RECORD(new BigDecimal(-1));
        msgHeader.setPROVINCE_CODE("CQ");
        msgHeader.setROUTE_CODE("ERP");
        req.setMSGHEADER(msgHeader);

        OutputParameters outputParameters = null;
        try {
            outputParameters = osb_bp_mdm_hq_pageInquiryVendorSrvProxy.process(req);

        } catch (RemoteException e) {
            e.printStackTrace();
        }
        return "dd";
    }

webservices地址

SpringBoot整合webService类参数方式调用_第4张图片

报错问题

SpringBoot整合webService类参数方式调用_第5张图片
解决方法
SpringBoot整合webService类参数方式调用_第6张图片
添加package-info.java文件

@javax.xml.bind.annotation.XmlSchema(namespace = "http://soa.cmcc.com/SB_SC_PO_PageInquiryVendorInfoSrv", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package com.cmcc.soa.OSB_BP_MDM_HQ_PageInquiryVendorSrv;

你可能感兴趣的:(远程调用,spring,boot,java,websocket)