日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

CXF学习(2) helloworld

發布時間:2023/12/1 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CXF学习(2) helloworld 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?

0.新建一個項目取名wsserver. pom.xml 文件如下

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>sidonia</groupId><artifactId>wsserver</artifactId><version>0.0.1-SNAPSHOT</version><properties><cxf.version>3.1.4</cxf.version></properties><dependencies><dependency><groupId>org.apache.cxf</groupId><artifactId>cxf-rt-frontend-jaxws</artifactId><version>${cxf.version}</version></dependency><dependency><groupId>org.apache.cxf</groupId><artifactId>cxf-rt-transports-http</artifactId><version>${cxf.version}</version></dependency><dependency><groupId>org.apache.cxf</groupId><artifactId>cxf-rt-frontend-jaxrs</artifactId><version>${cxf.version}</version></dependency><dependency><groupId>org.apache.cxf</groupId><artifactId>cxf-rt-transports-http-jetty</artifactId><version>${cxf.version}</version></dependency></dependencies> </project>

?

1.新建一個interface 取名 HelloWorld

package com.test.hello;import javax.jws.WebService;@WebService public interface HelloWorld {public void sayHello(); }

2.新建一個實現類,取名HelloWorldImpl

package com.test.hello;import javax.jws.WebService;@WebService(endpointInterface="com.test.hello.HelloWorld",serviceName="HelloWorldWS") public class HelloWorldImpl implements HelloWorld{public void sayHello() {System.out.println("hello world");} }

?3.新建一個包含main方法的ServerMain類

public class ServerMain {public static void main(String[] args) throws Exception {HelloWorld helloWorldImpl = new HelloWorldImpl();Endpoint.publish("http://localhost:1234/ws", helloWorldImpl);System.out.println("webservice 暴露成功");} }

?4.這時候訪問上面這個地址,就可以看見下面這個xml

<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://hello.test.com/"xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http"name="HelloWorldWS" targetNamespace="http://hello.test.com/"><wsdl:types><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"xmlns:tns="http://hello.test.com/" elementFormDefault="unqualified"targetNamespace="http://hello.test.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:complexType><xs:complexType name="sayHelloResponse"><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="HelloWorld"><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="HelloWorldWSSoapBinding" type="tns:HelloWorld"><soap:binding style="document"transport="http://schemas.xmlsoap.org/soap/http" /><wsdl:operation name="sayHello"><soap:operation soapAction="" style="document" /><wsdl:input name="sayHello"><soap:body use="literal" /></wsdl:input><wsdl:output name="sayHelloResponse"><soap:body use="literal" /></wsdl:output></wsdl:operation></wsdl:binding><wsdl:service name="HelloWorldWS"><wsdl:port binding="tns:HelloWorldWSSoapBinding" name="HelloWorldImplPort"><soap:address location="http://localhost:1234/ws" /></wsdl:port></wsdl:service> </wsdl:definitions>

5.現在寫客戶端 取名wsclient

6.cmd 到D盤找個合適的地方?命令行執行?wsdl2java http://localhost:1234/ws?wsdl,這時候這里就會根據這個wsdl生成相應的類,把它考到客戶端項目下面

7.新建一個ClientMain類

package com.test.hello;public class ClientMain {public static void main(String[] args) {HelloWorldWS factory = new HelloWorldWS(); //顯然HelloWorldWS是一個工廠類HelloWorld helloWorld = factory.getHelloWorldImplPort();helloWorld.sayHello();} }

一運行,服務器端控制臺就會打印出hello world

?

轉載于:https://www.cnblogs.com/heben/p/5391311.html

總結

以上是生活随笔為你收集整理的CXF学习(2) helloworld的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。