当前位置:网站首页>Simple getting started example of Web Service
Simple getting started example of Web Service
2022-07-05 20:53:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack , I've prepared for you today Idea Registration code .
Web Service A simple introduction example
We generally achieve Web Service There are many ways to do this . I mainly used CXF Apache Plug ins and Axis 2 Two kinds of .
Web Service It is an online service solution provided by application service providers to solve every problem , It mainly adopts SOAP(Simple Object Access Protocol) agreement , The transmission data format uses XML Format to describe narration . Therefore, it also has the characteristics of cross platform .
web Widely used technology :
- TCP/IP: Universal Network protocol . Used by various devices
- HTML( Standard universal markup language Next application ): Universal user interface , Able to use HTML The label displays data
- Java: Write a generic that can be executed on any system programing language , because java With cross platform features
- XML( Standard universal markup language Next subset ): Universal data representation language , stay web Upload structured data easy Method
Their characteristic is their openness . Cross-platform sex , Openness is just Web services The basis of .
Here are the USES CXF Apache Plug in implementation of Web Service A simple example of getting started
1======== Create a new service interface
package com.clark;
import javax.jws.WebParam; import javax.jws.WebService;
@WebService public interface IHelloWorld { public String sayHello(@WebParam(name=”name”)String name); public int plus(int a,int b); } 2======== Service interface implementation class
package com.clark.impl;
import com.clark.IHelloWorld;
public class HelloWorldImpl implements IHelloWorld {
@Override public String sayHello(String name) { return “Hello Wolrd ,”+name; }
@Override public int plus(int a, int b) { return a+b; }
}
3============ Server side
package com.clark.service;
import javax.xml.ws.Endpoint;
import com.clark.impl.HelloWorldImpl;
public class WebServiceApp { public static void main(String[] args) { System.out.println(“web service start”); HelloWorldImpl implementor = new HelloWorldImpl(); String address = “http://localhost:8080/IHelloWorld”; Endpoint.publish(address, implementor); System.out.println(“web service started”); } }
4============client( The following is mainly aimed at Java Ordinary program ) package com.clark.client;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import com.clark.IHelloWorld;
public class HelloWorldClient { public static void main(String[] args) { JaxWsProxyFactoryBean svr = new JaxWsProxyFactoryBean(); svr.setServiceClass(IHelloWorld.class); svr.setAddress(“http://localhost:8080/CXFWebService/service/IHelloWorld”); IHelloWorld hw = (IHelloWorld) svr.create(); String name = hw.sayHello(” CXF Apache implements Web Service”); int result = hw.plus(2, 3); System.out.println(name); System.out.println(result); } }
4==============client( in the light of Spring In the integration Web Service Of Web Development ) package com.clark.web;
import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.clark.IHelloWorld;
public class HelloWorldClient { public static void main(String[] args) { System.out.println(“Web Service start……….”); ApplicationContext context = new ClassPathXmlApplicationContext(“applicationContext.xml”); IHelloWorld helloWorld = (IHelloWorld)context.getBean(“client”); String name = helloWorld.sayHello(“1111111111”); int result = helloWorld.plus(3, 4); System.out.println(name+” “+result); System.out.println(“Web Service end……….”); } }
5============Spring Of applicationContext.xml To configure <?xml version=”1.0″ encoding=”UTF-8″?
> <beans xmlns=”http://www.springframework.org/schema/beans” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:jaxws=”http://cxf.apache.org/jaxws” xsi:schemaLocation=” http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd”>
<jaxws:endpoint id=”helloWorld” implementor=”com.clark.impl.HelloWorldImpl” address=”/IHelloWorld” /> <bean id=”client” class=”com.clark.IHelloWorld” factory-bean=”clientFactory” factory-method=”create”/> <bean id=”clientFactory” class=”org.apache.cxf.jaxws.JaxWsProxyFactoryBean”> <property name=”serviceClass” value=”com.clark.IHelloWorld”/> <property name=”address”
value=”http://localhost:8080/CXFWebService/service/IHelloWorld”/> </bean> </beans>
6=============Spring In the integration Web Service service (CXF Servlet Configuration of ),web.xml <?
xml version=”1.0″ encoding=”UTF-8″?> <web-app xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns=”http://java.sun.com/xml/ns/javaee” xsi:schemaLocation=”http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd” id=”WebApp_ID” version=”2.5″> <display-name>CXFWebService</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <context-param> <param-name>contextConfigLocation</param-name> <!– <param-value>classpath:applicationContext.xml</param-value> –> <param-value>WEB-INF/applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>CXFServlet</servlet-name> <display-name>CXFServlet</display-name> <servlet-class> org.apache.cxf.transport.servlet.CXFServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet>
<servlet-mapping> <servlet-name>CXFServlet</servlet-name> <url-pattern>/service/*</url-pattern> </servlet-mapping> </web-app>
7============= Start the service , Address field input http://localhost:8080/CXFWebService/service/IHelloWorld?
wsdl You can see the corresponding SOAP Agreement in specification OK
Copyright notice : This article is an original blog article , Blog , Without consent , Shall not be reproduced .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/117642.html Link to the original text :https://javaforall.cn
边栏推荐
- NPDP如何续证?操作指南来了!
- Phpstudy Xiaopi's MySQL Click to start and quickly flash back. It has been solved
- Use of form text box (II) input filtering (synthetic event)
- Abnova e (diii) (WNV) recombinant protein Chinese and English instructions
- wpf 获取datagrid 中指定行列的DataGridTemplateColumn中的控件
- 中国管理科学研究院凝聚行业专家,傅强荣获智库专家“十佳青年”称号
- Abnova丨E (DIII) (WNV) 重组蛋白 中英文说明书
- XML建模
- 判断横竖屏的最佳实现
- Abnova blood total nucleic acid purification kit pre installed relevant instructions
猜你喜欢
Abnova e (diii) (WNV) recombinant protein Chinese and English instructions
重上吹麻滩——段芝堂创始人翟立冬游记
Duchefa丨D5124 MD5A 培养基中英文说明书
基於flask寫一個接口
解析创客教育的知识迁移和分享精神
haas506 2.0开发教程 - 阿里云ota - pac 固件升级(仅支持2.2以上版本)
Who the final say whether the product is good or not? Sonar puts forward performance indicators for analysis to help you easily judge product performance and performance
leetcode:1755. 最接近目标值的子序列和
Duchefa s0188 Chinese and English instructions of spectinomycin hydrochloride pentahydrate
Duchefa low melting point agarose PPC Chinese and English instructions
随机推荐
ts 之 泛型
MySQL fully parses json/ arrays
Abnova e (diii) (WNV) recombinant protein Chinese and English instructions
Which securities is better for securities account opening? Is online account opening safe?
Maker education infiltrating the transformation of maker spirit and culture
ODPS 下一个map / reduce 准备
基於flask寫一個接口
systemd-resolved 开启 debug 日志
Duchefa s0188 Chinese and English instructions of spectinomycin hydrochloride pentahydrate
ts 之 属性的修饰符public、private、protect
Promouvoir le développement de l'industrie culturelle et touristique par la recherche, l'apprentissage et l'enseignement pratique du tourisme
bazel是否有学习的必要
Abnova丨荧光染料 620-M 链霉亲和素方案
教你自己训练的pytorch模型转caffe(二)
Abbkine丨TraKine F-actin染色试剂盒(绿色荧光)方案
中国管理科学研究院凝聚行业专家,傅强荣获智库专家“十佳青年”称号
Make Jar, Not War
XML建模
Is it safe to open a stock account by mobile phone? My home is relatively remote. Is there a better way to open an account?
ClickHouse 复制粘贴多行sql语句报错