I Web Service Working Principles
Web Service, also known as XML Web Service WebService, is a request that can receive from other systems from Internet or Intranet. Lightweight independent independent Communication Technology. Yes: A software service delivered over the Web via SOAP, described using a WSDL file, and registered via UDDI.
WSDL: (Web Services Description Language) A WSDL file is an XML document that describes a set of SOAP messages and how to exchange them. In most cases automatically generated and used by software.
UDDI (Universal Description, Discovery, and Integration) is a new project mainly aimed at Web service providers and users. Before users can call a Web service, they must determine which business methods are included in the service, find the called interface definition, and compile software on the server side. UDDI is a mechanism that guides the system to find the corresponding service based on the description document. UDDI uses SOAP messaging mechanism (standard XML/HTTP) to publish, edit, browse and find registration information. It uses XML format to encapsulate various types of data, and sends it to the registration center or the registration center returns the required data.
2. Calling Principle
Implementing a complete Web service includes the following steps:
◆ The Web service provider designs and implements the Web service, and publishes the correctly debugged Web service through the Web service intermediary, and Register in the UDDI registration center; (Release)
◆ The Web service requester requests a specific service from the Web service intermediary, and the intermediary queries the UDDI registration center according to the request to find services that satisfy the request for the requester; (Discovery)
3. Calling method:
1. A simple and flexible method to dynamically call WebService using GET/POST/SOAP under Net (C#)There are 3 ways to call webservice1) . httpget2). httppost
3). The advantage of httpsoap soap is that it can pass structured data, but the first two cannot.btw, soap ultimately uses HTTP to transmit Steps:
1. Prepare the jar package needed for development [apache-cxf-2.5.9 download] 🎜🎜🎜🎜🎜2. Develop a webservice business interface, and use @WebService to modify the method. 🎜package com.ywx; import javax.jws.WebService; @WebService public interface HelloWorld { String sayHi(String name); }
package com.ywx.impl; import java.util.Date; import javax.jws.WebService; import com.ywx.HelloWorld; @WebService(endpointInterface="com.ywx.HelloWorld",serviceName="HelloWorldWs")//指定webservice所实现的接口以及服务名称 public class HellowWorlds implements HelloWorld{ @Override public String sayHi(String name) { return name+"您好!现在时间是:"+new Date(); } }
package com.ywx.lee; import javax.xml.ws.Endpoint; import com.ywx.HelloWorld; import com.ywx.impl.HellowWorlds; public class ServiceMain { public static void main(String args[]){ HelloWorld hw = new HellowWorlds(); //调用Endpoint的publish方法发布Web Service Endpoint.publish("192.168.1.7/vashon", hw); System.out.println("Web Service暴露成功!"); } }
二、使用CXF开发Web Service客户端:
步骤:
1、新建一个客户端工程
2、调用CXF提供的wsdl2java工具或使用eclipse/myeclipse的new Web Service生成客户端代码(这里使用第二种方式):
输入wsdl链接:
点击next:
选择生成客户端代码的位置:
点击finish,生成客户端代码如下:
3、在客户端写测试类测试:
package com.ywx.test; import java.rmi.RemoteException; import com.ywx.HelloWorldProxy; public class TestService { public static void main(String args[]){ HelloWorldProxy h = new HelloWorldProxy(); try { String s = h.sayHi("yangwenxue"); System.out.println("调webservice:"+s); } catch (RemoteException e) { e.printStackTrace(); } } }
运行结果(传入一个参数,调用Web Service返回的字符串结果如下):
其调用生成的格式已经有服务端定义好了,看上面贴出来的代码或者下面的截图说明:
Web Service服务端和客户端工程结果截图如下:
更多Webservice working principle and examples相关文章请关注PHP中文网!