day63-webservice 04.JaxWsServerFactoryBean和SOAP1.2

Posted 绿茵好莱坞

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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...");
   }
}

 

以上是关于day63-webservice 04.JaxWsServerFactoryBean和SOAP1.2的主要内容,如果未能解决你的问题,请参考以下文章

自学it18大数据笔记-第一阶段Java-day09-day10-day11-day12-day13-day14-day15

自学it18大数据笔记-第一阶段Java-day16-day17-day18-day19--day20-day21-day22——会持续更新

伸手党福利文,Python入门大全

目录大纲

自学it18大数据笔记-第一阶段Java-day05-day06-day07-day08

day56(2023.4.25)