http://blog.csdn.net/yaerfeng/article/details/8352307
Example of WEBSERVICE quick start:
First define the interface:
< div class="tools" style="padding:3px 8px 10px 10px; font-size:9px; line-height:normal; font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; color:silver; border- left-width:3px; border-left-style:solid; border-left-color:rgb(153,153,153)">
[java] view plain
copy< /span>
print ?
- packagecom.whaty.platform.ws.server;
-
importjavax.jws.WebService;
-
-
-
-
-
-
-
-
< li style="margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style :decimal-leading-zero outside; color:rgb(255,153,153); line-height:18px; background-color:rgb(85,85,85)"> @WebService
- < span class="keyword" style="margin:0px; padding:0px; border:none; color:rgb(102,204,255); font-weight:bold; background-color:inherit">publicinterface IMyservice{
-
- intadd(inta,intb);
-
- intminus(< /span>int a,int B);
- }
Next, write the implementation class:
- packagecom.whaty.platform.ws.server;
-
- importjavax.jws.WebService; li>
-
-
-
-
-
- < /li>
-
-
- @WebService(endpointInterface=“com.whaty.platform.ws.server.IMyservice”)
- publicclass MyServiceImplimplementsIMyservice{
-
- publicint add(inta, intb){
- System.out.println(“a+b=”+(a+b));
- return a+b;
-
-
- publicintminus(inta,intb){
- System.out.println(“ab=”+(ab));
- returnab;
- }
-
- }
最后发布我们的服务,直接右键运行main方法,如果控制台没报错,多半是发布成功了,否则检查你的代码:
- package com.whaty.platform.ws.server;
-
- import javax.xml.ws.Endpoint;
-
-
-
-
-
-
-
- public class MyServer {
- public static void main(String[] args) {
-
- String address=“http://localhost:7777/tudou”;
- Endpoint.publish(address, new MyServiceImpl());
- }
- }
浏览器地址栏输入:访问webservice看看是否发布成功【地址后面加上”?wsdl”】:
http://localhost:7777/tudou?wsdl
浏览器显示如下:
- This XML file does not appear to have any style information associated with it. The document tree is shown below.
-
-
- <definitions xmlns:soap=“http://schemas.xmlsoap.org/wsdl/soap/” xmlns:tns=“http://server.ws.platform.whaty.com/” xmlns:xsd=“http://www.w3.org/2001/XMLSchema” xmlns=“http://schemas.xmlsoap.org/wsdl/” targetNamespace=“http://server.ws.platform.whaty.com/” name=“MyServiceImplService”>
- <types>
- <xsd:schema>
- <xsd:import namespace=“http://server.ws.platform.whaty.com/” schemaLocation=“http://localhost:7777/tudou?xsd=1”/>
- xsd:schema>
- types>
- <message name=“minus”>
- <part name=“parameters” element=“tns:minus”/>
- message>
- <message name=“minusResponse”> < /span>
- <part name=“parameters” element=“tns:minusResponse”/>
- message>
- <message name=“add”>
- <part name=“parameters” element=“tns:add”/>
- message>
- <message name=“addResponse”>
- <part name=“parameters” element=“tns:addResponse”/>
- message>
- <portType name=“IMyservice”>
- <operation name=“minus”>
- <input message=“tns:minus”/>
- <output message=“tns:minusResponse”/>
- operation>
- <operation name=“add”>
- <input message=“tns:add”/>
- <output message=“tns:addResponse”/>
- operation>
- portType>
- <binding name=“MyServiceImplPort Binding” type=“tns:IMyservice”>
- <soap:binding transport=“http://schemas.xmlsoap.org/soap/http” style=“document”/>
- <operation name=“minus”>
- <soap:operation soapAction=“”/>
- <input>
- <soap:body use=“literal”/>
- input>
- <output>
- <soap:body use=“literal”/>
- output>
- operation>
- <operation name=“add”>
- <soap:operation soapAction=“”/>
- <input>
- <soap:body use=“literal”/>
- input>
- <output>
- <soap:body use=“literal”/>
- output>
- operation>
- bin ding>
- <service name=“MyServiceImplService”>
- <port name=“MyServiceImplPort” binding=< span class="attribute-value" style="margin:0px; padding:0px; border:none; color:rgb(255,255,255); background-color:inherit">“tns:MyServiceImplPortBinding”>
- <soap:address location=“http://localhost:7777/tudou”/>
- port>
- service>
- definitions>
下面我们创建客户端访问:
- package com.whaty.platform.ws.client;
-
- import java.net.MalformedURLException;
- import java.net.URL;
-
- import javax.xml.namespace.QName;
- import javax.xml.ws.Service;
-
- < span class="keyword" style="margin:0px; padding:0px; border:none; color:rgb(102,204,255); font-weight:bold; background-color:inherit">import com.whaty.platform.ws.server.IMyservice;
-
-
-
-
-
-
-
- public class MyClient {
- public static void main(String[] args) {
-
- try {
-
- URL url = new URL(“http://localhost:7777/tudou?wsdl”);
-
-
-
- QName qname=new QName(“http://server.ws.platform.whaty.com/”,“MyServiceImplService”);
- Service service=Service.create(url, qname);
- IMyservice ms=service.getPort(IMyservice.class);
- ms.add(1, 4);
- ms.minus(1, 4);
- } catch (MalformedURLException e) {
- e.printStackTrace();
- }
- }
- }
控制台打印如下:
a+b=5 a-b=-3
- package com.whaty.platform.ws.server; span>
-
- import javax.jws.WebService;
-
-
-
-
-
-
-
-
- @WebService
- public interface IMyservice {
-
- int add(int a, int b);
-
- int minus(int a, int b);
- }
[java] view plain copy
print ?
- package com.whaty.platform.ws.server;
-
- import javax.jws.WebService;
-
-
-
-
-
-
-
[java] view plain copy
print ?
-
- @WebService(endpointInterface=“com.whaty.platform.ws.server.IMyservice”)
- public class MyServiceImpl implements IMyservice {
-
- public int add(int a, int b) {
- System.out.println(“a+b=”+(a+b));
- return a+b;
- }
-
- public int minus(int a, int b) {
- System.out.println(“a-b=”+(a-b));
- return a-b;
- }
-
- }
[java] view plain copy
print ?
- package com.whaty.platform.ws.server;
-
- import javax.xml.ws.Endpoint;
-
-
-
-
-
-
-
- public class MyServer {
- public static void main(String[] args) {
-
- String address=“http://localhost:7777/tudou”;
- Endpoint.publish(address, new MyServiceImpl());
- }
- }
[java] view plain copy
print ?
- This XML file does not appear to have any style information associated with it. The document tree is shown below.
-
-
- <definitions xmlns:soap=“http://schemas.xmlsoap.org/wsdl/soap/” xmlns:tns=“http://server.ws.platform.whaty.com/” xmlns:xsd=“http://www.w3.org/2001/XMLSchema” xmlns=“http://schemas.xmlsoap.org/wsdl/” targetNamespace=“http://server.ws.platform.whaty.com/” name=“MyServiceImplService”>
- <types>
- <xsd:schema>
- <xsd:import namespace=“http://server.ws.platform.whaty.com/” schemaLocation=“http://localhost:7777/tudou?xsd=1”/> < /span>
- xsd:schema>
- types>
- <message name=“minus”>
- <part name=“parameters” element=“tns:minus”/>
- message>
- <message name=“minusResponse”>
- <part name=“parameters” element=“tns:minusResponse”/>
- message>
- <message name=“add”>
- <part name=“parameters” element=“tns:add”/>
- message>
- <message name=“addResponse “>
- <part name=“parameters” element=“tns:addResponse”/> span>
- message>
- <portType name=“IMyservice”>
- <operation name=“minus”>
- <input message=“tns:minus”/>
- <output message=“tns:minusResponse”/>
- operation>
- <operation name=“add”>
- <input message=“tns:add”/>
- <output message=“tns:addResponse” />
- operation>
- portType>
- <binding name=“MyServiceImplPortBinding” type=“tns:IMyservice”>
- <soap:binding transport=“http://schemas.xmlsoap.org/soap/http” style=“document”/>
- <operation name=“minus”>
- <soap:operation soapAction=“”/>
- <input>
- <soap:body use=“literal”/>
- input>
- <output>
- <soap:body use=“literal”/>
- output>
- operation>
- <operation name=“add”>
- <soap:operation soapAction=“”/>
- <input>
- <soap:body use=“literal”/>
- input>
- <output>
- <soap:body use=“literal”/>
- output>
- operation>
- < /binding>
- <service name=“MyServiceImplService”>
- <port name=“MyServiceImplPort” binding=“tns:MyServiceImplPortBinding”>
- <soap:address location=“http://localhost:7777/tudou”/>
- port>
- service>
- definitions>
[html] view plain copy
print ?
- package com.whaty.platform.ws.client;
-
- import java.net.MalformedURLException;
- import java.net.URL;
-
- import javax.xml.namespace.QName;
- impor t javax.xml.ws.Service;
-
- import com.whaty.platform.ws.server.IMyservice;
-
-
-
-
-
-
-
- public class MyClient {
- public static void main(String[] args) {
-
- try {
-
- URL url = new URL(“http://localhost:7777/tudou?wsdl”);
-
-
-
- QName qname=new QName(“http://server.ws.platform.whaty.com/”,“MyServiceImplService”);
- Service service=Service.cre ate(url, qname);
- IMyservice ms=service.getPort(IMyservice.class);
- ms.add(1, 4);
- ms.minus(1, 4);
- } catch (Malfor medURLException e) {
- e.printStackTrace();
- }
- }
- }
[java] view plain copy
print ?
WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3477 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC