zoukankan      html  css  js  c++  java
  • day63-webservice 04.JaxWsServerFactoryBean和SOAP1.2

    <wsdl:definitions xmlns:ns1="http://schemas.xmlsoap.org/soap/http" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="http://server.cxf.rl.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="HelloServiceService" targetNamespace="http://server.cxf.rl.com/">
    <wsdl:types>
    <xs:schema xmlns:tns="http://server.cxf.rl.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified" targetNamespace="http://server.cxf.rl.com/" version="1.0">
    <xs:element name="sayHello" type="tns:sayHello"/>
    <xs:element name="sayHelloResponse" type="tns:sayHelloResponse"/>
    <xs:complexType name="sayHello">
    <xs:sequence>
    <xs:element minOccurs="0" name="arg0" type="xs:string"/>
    </xs:sequence>
    </xs:complexType>
    <xs:complexType name="sayHelloResponse">
    <xs:sequence>
    <xs:element minOccurs="0" name="return" type="xs:string"/>
    </xs:sequence>
    </xs:complexType>
    </xs:schema>
    </wsdl:types>
    <wsdl:message name="sayHello">
    <wsdl:part element="tns:sayHello" name="parameters"></wsdl:part>
    </wsdl:message>
    <wsdl:message name="sayHelloResponse">
    <wsdl:part element="tns:sayHelloResponse" name="parameters"></wsdl:part>
    </wsdl:message>
    <wsdl:portType name="HelloService">
    <wsdl:operation name="sayHello">
    <wsdl:input message="tns:sayHello" name="sayHello"></wsdl:input>
    <wsdl:output message="tns:sayHelloResponse" name="sayHelloResponse"></wsdl:output>
    </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="HelloServiceServiceSoapBinding" type="tns:HelloService">
    <soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="sayHello">
    <soap12:operation soapAction="" style="document"/>
    <wsdl:input name="sayHello">
    <soap12:body use="literal"/>
    </wsdl:input>
    <wsdl:output name="sayHelloResponse">
    <soap12:body use="literal"/>
    </wsdl:output>
    </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="HelloServiceService">
    <wsdl:port binding="tns:HelloServiceServiceSoapBinding" name="HelloServicePort">
    <soap12:address location="http://127.0.0.1:5555/hello"/>
    </wsdl:port>
    </wsdl:service>
    </wsdl:definitions>

    http://www.cnblogs.com/yanzige/p/5377332.html


    package com.rl.cxf.client;
    
    import com.rl.soap11.HelloService;
    import com.rl.soap11.HelloServiceService;
    
    public class Soap11Client {
       public static void main(String[] args) {
           HelloServiceService hss = new HelloServiceService();
           HelloService hs = hss.getHelloServicePort();
           String result = hs.sayHello("lisi");
           System.out.println(result);
           
    }
    }
    package com.rl.cxf.client;
    
    import com.rl.cxf.server.HelloService;
    import com.rl.cxf.server.HelloServiceService;
    
    public class Soap12Client {
       public static void main(String[] args) {
           HelloServiceService hss = new HelloServiceService();
           HelloService hs = hss.getHelloServicePort();
           String result = hs.sayHello("lisi");
           System.out.println(result);
           
    }
    }
    package com.rl.cxf.server;
    
    import javax.jws.WebService;
    import javax.xml.ws.BindingType;
    
    @WebService
    //@BindingType(value=javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING )
    @BindingType(value=javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING )
    public class HelloService {    
         public String sayHello(String name){
             return name + " hello";
         }
    }
    package com.rl.cxf.server;
    
    //import org.apache.cxf.frontend.ServerFactoryBean;
    import org.apache.cxf.interceptor.LoggingInInterceptor;
    import org.apache.cxf.interceptor.LoggingOutInterceptor;
    import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
    
    public class MyCXFServer {
       public static void main(String[] args) {
         //创建服务工厂对象
         //ServerFactoryBean sfb = new ServerFactoryBean();
         JaxWsServerFactoryBean sfb = new JaxWsServerFactoryBean();
         //加入输入输出拦截器
         sfb.getInInterceptors().add(new LoggingInInterceptor());
         //sfb.getOutFaultInterceptors().add(new LoggingOutInterceptor());
         sfb.getOutInterceptors().add(new LoggingOutInterceptor());
         //指定服务地址
         sfb.setAddress("http://127.0.0.1:5555/hello");
         //设置服务类
         sfb.setServiceClass(HelloService.class);
         //设置服务类的实例对象
         sfb.setServiceBean(new HelloService());
         //发布服务
         sfb.create();
         System.out.println("server ready...");
       }
    }
  • 相关阅读:
    hdu5628 Clarke and math
    LOJ#2452. 「POI2010」反对称 Antisymmetry
    LOJ#2444. 「NOI2011」阿狸的打字机
    BZOJ2795: [Poi2012]A Horrible Poem
    LOJ#2427. 「POI2010」珍珠项链 Beads
    云主机文件系统readonly处理案例
    兼容性测试中如何切换和管理多个JDK版本
    Promise之你看得懂的Promise
    一次MySQL线上慢查询分析及索引使用
    考拉消息中心消息盒子处理重构(策略模式)
  • 原文地址:https://www.cnblogs.com/ZHONGZHENHUA/p/7654372.html
Copyright © 2011-2022 走看看