`

WS summary

阅读更多

<!--[if !supportLists]-->1.         <!--[endif]-->Create a ws project “JasperReportProject”

 

2.  Write some classes needed to be accessed or deployed.

           

@WebService(name="Example", targetNamespace="http://www.jsoso.com/wstest", serviceName="Example")

@SOAPBinding(style=Style.DOCUMENT)

public class Example {

           

            private ArrayList<Person> persons = new ArrayList<Person>();;

           

           

            @WebMethod(operationName="toSayHello",action="sayHello",exclude=false)

            @WebResult(name="returnWord")

            public String sayHello(@WebParam(name="userName")String userName) {

                        return "Hello:" + userName;

            }

}

 

3.  I deploy WS in Tomcat, config files is must: sun-jaxws.xml and web.xml

  

   Web.xml:

            // WSServletContextListener.java is must

<listener>

     <listener-class>

        com.sun.xml.ws.transport.http.servlet.WSServletContextListener

     </listener-class>

   </listener>

 

    <servlet>

      <servlet-name>ladss</servlet-name>

      <servlet-class>

        com.sun.xml.ws.transport.http.servlet.WSServlet

      </servlet-class>

   </servlet>

  

    <servlet-mapping>

     <servlet-name>ladss</servlet-name>

     <url-pattern>/test</url-pattern>

   </servlet-mapping>

  

 

 

 

sun-jaxws.xml:

<?xml version="1.0" encoding="UTF-8"?>

<endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" version="2.0">

    <endpoint

     name="test"

     implementation="com.acs.ws.servicer.Example"

     url-pattern="/test">        

     </endpoint> 

</endpoints>

 

Note: url-pattern “/test” should match with ‘/test’ in web.xml

 

4.  the following Jars must included for running web service normally.

 

            Webservices-rt.jar and webservices-tools.jar

 

5.         publish web-services: you should first start application server, and then run this class.

            You could open the browser and view wsdl.

public class PublishFunction {

      public static void main(String[] args) {

             Endpoint.publish(

                     "http://localhost:8080/WebServiceExample",

                     new CircleFunctions());

      }

}

Please be advised that Out of the box, The Endpoint publisher handles one client request at a time. This is fine for getting web services up and running in development mode. However, if  the processing of a given request should hang, then all other client requests are effectively blocked. An example at the end of this chapter show how endpoint can handle request concurrently so that one hung request does not block the others.

 

6.  wsgen & wsimport

 

            Wsgen: navigate to the directory of your project where service endpoint exists.

C:\perforce\WebServiceExample>wsgen -cp ./build/classes -d ./bin -r ./wsdl -s ./

src -wsdl hello.CircleFunctions

wsgen -cp ./build/classes -d ./bin -r ./wsdl -s ./ src -wsdl hello.CircleFunctions

 

Usage: WSGEN [options] <SEI>

where [options] include:

  -classpath <path>          specify where to find input class files

  -cp <path>                 same as -classpath <path>

  -d <directory>             specify where to place generated output files

  -extension                 allow vendor extensions - functionality not specified

                             by the specification.  Use of extensions may

                             result in applications that are not portable or

                             may not interoperate with other implementations

  -help                      display help

  -keep                      keep generated files

  -r <directory>             resource destination directory, specify where to

                             place resouce files such as WSDLs

  -s <directory>             specify where to place generated source files

  -verbose                   output messages about what the compiler is doing

  -version                   print version information

  -wsdl[:protocol]           generate a WSDL file.  The protocol is optional.

                             Valid protocols are soap1.1 and Xsoap1.2, the default

                             is soap1.1.  Xsoap1.2 is not standard and can only

be

                             used in conjunction with the -extension option

  -servicename <name>        specify the Service name to use in the generated WSDL

                             Used in conjunction with the -wsdl option.

  -portname <name>           specify the Port name to use in the generated WSDL

                             Used in conjunction with the -wsdl option.

Wsimport

C:\perforce\TestWSClient>wsimport -d ./bin -s ./src -p com.acs.ws.testcirlefunct

ions http://localhost:8080/WebServiceExample/test?wsdl

 

7.  There are the basic steps for creating web service and client:

            1. Code the implementation class.

            2. Compile the implementation class.

            3. Use wsgen to generate the artifacts required to deploy the service.

            4. Package the files into aWARfile.

            5. Deploy theWARfile. The web service artifacts (which are used to                         communicate with clients) are generated by the Application Server during deployment.

            6. Code the client class.

            7. Use wsimport to generate and compile the web service artifacts needed to connect to the

            service.

            8. Compile the client class.

            9. Run the client.

The sections that follow cover these steps in greater detail.

 

6.         WS command:

            wsgenwsimport命令说明

wsgen
wsgen是在JDKbin目录下的一个exe文件(Windows版),该命令的主要功能是用来生成合适的JAX-WS。它读取Web Service的终端类文件,同时生成所有用于发布Web Service所依赖的源代码文件和经过编译过的二进制类文件。这里要特别说明的是,通常在Web Service Bean中用到的异常类会另外生成一个描述Bean,如果Web Service Bean中的方法有声明抛出异常,这一步是必需的,否则服务器无法绑定该对像。此外,wsgen还能辅助生成WSDL和相关的xsd文件。wsgen从资源文件生成一个完整的操作列表并验证web service是否合法,可以完整发布。
命令参数说明:

  • u -cp 定义classpath
  • u -r 生成 beanwsdl文件的存放目录
  • u -s 生成发布Web Service的源代码文件的存放目录(如果方法有抛出异常,则会生成该异常的描述类源文件)
  • u -d 生成发布Web Service的编译过的二进制类文件的存放目录(该异常的描述类的class文件)


命令范例:wsgen -cp ./bin -r ./wsdl -s ./src -d ./bin -wsdl org.jsoso.jws.server.Example

wsimport
wsimport也是在JDKbin目录下的一个exe文件(Windows版),主要功能是根据服务端发布的wsdl文件生成客户端存根及框架,负责 与Web Service 服务器通信,并在将其封装成实例,客户端可以直接使用,就像使用本地实例一样。对Java而言,wsimport帮助程序员生存调用web service所需要的客户端类文件.java.class。要提醒指出的是,wsimport可以用于非Java的服务器端,如:服务器端也许是C# 编写的web service,通过wsimport则生成Java的客户端实现。
命令参数说明:

  • u -d 生成客户端执行类的class文件的存放目录
  • u -s 生成客户端执行类的源文件的存放目录
  • u -p 定义生成类的包名


命令范例:wsimport -d ./bin -s ./src -p org.jsoso.jws.client.ref http://localhost:8080/hello?wsdl

 

 

<!--[if !supportLists]-->7.   <!--[endif]-->WS Annotation:

JAX-WS 注释

基于 XML Web Service Java API”JAX-WS)通过使用注释来指定与 Web Service 实现相关联的元数据以及简化 Web Service 的开发。注释描述如何将服务器端的服务实现作为 Web Service 来访问或者客户端的 Java 类如何访问 Web Service

JAX-WS 编程标准支持将具有用于定义服务端点应用程序的元数据的 Java 类作为 Web Service 来注释以及注释客户机可以如何访问 Web ServiceJAX-WS 支持使用基于 Metadata Facility for the Java Programming LanguageJava 规范请求(JSR175)规范和用于 Java 平台的 Web Service 元数据JSR 181)规范的注释,还可以使用由 JAX-WS 2.0JSR 224)规范定义的注释(包括 JAXB 注释)。通过使用符合 JSR 181 标准的注释,可以简单地注释服务实现类或服务接口,并且现在将应用程序作为 Web Service 来启用。通过在 Java 源代码中使用注释可以简化 Web Service 的开发和部署,因为会定义一些通常从部署描述符文件和 WSDL 文件中获得的附加信息,或者会将元数据从 XML WSDL 映射至源工件中。

使用注释来配置绑定、处理程序链、端口类型的集合名称、服务以及其他 WSDL 参数。注释用于将 Java 映射至 WSDL 和模式,以及在运行时控制 JAX-WS 运行时处理和响应 Web Service 调用的方式。

下表中列示了 JAX-WS 支持的注释。注释的目标适用于下列 Java 对象:

  • 诸如 Java 类、枚举或接口等类型
  • 方法
  • 用于表示 Java 类中局部实例变量的字段
  • Java 方法中的参数

Web Service 元数据注释(JSR 181

注释类:

注释:

属性:

javax.jws.WebService

当实现 Web Service 时,@WebService 注释标记 Java 类;实现 Web Service 接口时,标记服务端点接口(SEI)。

要点:

实现 Web Service Java 类必须指定 @WebService @WebServiceProvider 注释。不能同时提供这两种注释。

此注释适用于客户机/服务器 SEI JavaBeans 端点的服务器端点实现类。

如果注释通过 endpointInterface 属性引用了某个 SEI,那么还必须使用 @WebService 注释来注释该 SEI

请参阅适用于使用 @WebService 注释的类的方法的规则,以了解更多信息。

  • 注释目标:类型
  • 属性:

- name

wsdl:portType 的名称。缺省值为 Java 类或接口的非限定名称。(字符串)

- targetNamespace

指定从 Web Service 生成的 WSDL XML 元素的 XML 名称空间。缺省值为从包含该 Web Service 的包名映射的名称空间。(字符串)

- serviceName

指定 Web Service 的服务名称:wsdl:service。缺省值为 Java 类的简单名称 + Service。(字符串)

- endpointInterface

指定用于定义服务的抽象 Web Service 约定的服务端点接口的限定名。如果指定了此限定名,那么会使用该服务端点接口来确定抽象 WSDL 约定。(字符串)

- portName

wsdl:portName。缺省值为 WebService.name+Port。(字 符串)

- wsdlLocation

指定用于定义 Web Service WSDL 文档的 Web 地址。Web 地址可以是相对路径或绝对路径。(字符串)

javax.jws.WebMethod

@WebMethod 注释表示作为一项 Web Service 操作的方法。

将此注释应用于客户机或服务器 服务端点接口(SEI)上的方法,或者应用于 JavaBeans 端点的服务器端点实现类。

要点:

仅支持在使用 @WebService 注释来注释的类上使用 @WebMethod 注释。

  • 注释目标:方法
  • 属性:

- operationName

指定与此方法相匹配的 wsdl:operation 的名称。缺省值为 Java 方法的名称。(字符串)

- action

定义此操作的行为。对于 SOAP 绑定,此值将确定 SOAPAction 头的值。缺省值为 Java 方法的名称。(字符串)

- exclude

指定是否从 Web Service 中排除某一方法。缺省值为 false。(布尔 值)

javax.jws.Oneway

@Oneway 注释将一个方法表示为只有输入消息而没有输出消息的 Web Service 单向操作。

将此 注释应用于客户机或服务器服务端点接口(SEI)上的方法,或者应用于 JavaBeans 端点的服务器端点实现类。

  • 注释目标:方法
  • 没有适用于 Oneway 注释的属性。

javax.jws.WebParam

@WebParam 注释用于定制从单个参数至 Web Service 消息部件和 XML 元素的映射。

将 此注释应用于客户机或服务器服务端点接口(SEI)上的方法,或者应用于 JavaBeans 端点的服务器端点实现类。

  • 注释目标:参数
  • 属性:

- name

参数的名称。如果操作是远程过程调用(RPC)类型并且未指定 partName 属性,那么这是用于表示参数的 wsdl:part 属性的名称。如果操作是文档类型或者参数映射至某个头,那么 -name 是用于表示该参数的 XML 元素的局部名称。如果操作是文档类型、参数类型为 BARE 并且方式为 OUT INOUT,那么必须指定此属 性。(字符串)

- partName

定义用于表示此参数的 wsdl:part 属性的名称。仅当操作类型为 RPC 或者操作是文档类型并且参数类型为 BARE 时才使用此参数。(字符串)

- targetNamespace

指定参数的 XML 元素的 XML 名称空间。当属性映射至 XML 元素时,仅应用于文档绑定。缺省值为 Web Service targetNamespace。(字符串)

- mode

此值表示此方法的参数流的方向。有效值为 ININOUT OUT。(字符串)

- header

指定参数是在消息头还是消息体中。缺省值为 false。(布尔值)

javax.jws.WebResult

@WebResult 注释用于定制从返回值至 WSDL 部件或 XML 元素的映射。

将此注释应用于客户机 或服务器服务端点接口(SEI)上的方法,或者应用于 JavaBeans 端点的服务器端点实现类。

  • 注释目标:方法
  • 属性:

- name

当返回值列示在 WSDL 文件中并且在连接上的消息中找到该返回值时,指定该返回值的名称。对于 RPC 绑定,这是用于表示返回值的 wsdl:part 属性的名称。对于文档绑定,-name 参数是用于表示返回值的 XML 元素的局部名。对于 RPC DOCUMENT/WRAPPED 绑定,缺省值为 return。对于 DOCUMENT/BARE 绑定,缺省值为方法名 + Response。(字符串)

- targetNamespace

指定返回值的 XML 名称空间。仅当操作类型为 RPC 或者操作是文档类型并且参数类型为 BARE 时才使用此参数。(字符串)

- header

指定头中是否附带结果。缺省值为 false。(布尔值)

- partName

指定 RPC DOCUMENT/BARE 操作的结果的部件名称。缺省值为 @WebResult.name。(字 符串)

javax.jws.HandlerChain

@HandlerChain 注释用于使 Web Service 与外部定义的处理程序链相关联。

只能通过对 SEI 或实现类使用 @HandlerChain 注释来配置服务器端的处理程序。

但是可以使用多种方法来配置客户端的处理程序。可以通过对生成的服务类或者 SEI 使用 @HandlerChain 注释来配置客户端的处理程序。此外,可以按程序在服务上注册您自己的 HandlerResolver 接口实现,或者按程序在绑定对象上设置处理程序链。

  • 注释目标:类型
  • 属性:

- file

指定处理程序链文件所在的位置。文件位置可以是采用外部格式的绝对 java.net.URL,也可以是类文件中的相对路径。(字符串)

- name

指定配置文件中处理程序链的名称。(字符串)

javax.jws.SOAPBinding

@SOAPBinding 注释指定 Web Service SOAP 消息协议之间的映射。

将此注释应 用于客户机或服务器服务端点接口(SEI)上的类型或方法,或者应用于 JavaBeans 端点的服务器端点实现类。

方法级别的注释仅限于它可以指定的对象,仅当 style 属性为 DOCUMENT 时才使用该注释。如果未指定方法级别的注释,那么将使用类型的 @SOAPBinding 行为。

  • 注释目标:类型或方法
  • 属性:

- style

定义发送至 Web Service 和来自 Web Service 的消息的编码样式。有效值为 DOCUMENT RPC。缺省值为 DOCUMENT。(字 符串)

- use

定义用于发送至 Web Service 和来自 Web Service 的消息的格式。缺省值为 LITERALENCODED Feature Pack for Web Services 中不受支持。(字符串)

- parameterStyle

确定方法的参数是否表示整个消息体,或者参数是否是封装在执行操作之后命名的顶级元素中的元素。有效值为 WRAPPED BARE。对于 DOCUMENT 类型的绑定只能使用 BARE 值。缺省值为 WRAPPED。(字符串)

JAX-WS 注释(JSR 224

注释类:

注释:

属性:

javax.xml.ws.BindingType

@BindingType 注释指定在发布此类型的端点时要使用的绑定。

将此注释应用于 JavaBeans 端点或提供程序端点的服务器端点实现类。

要点:

可以通过将该注释的值指定为 javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_MTOM_BINDING javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_MTOM_BINDING 来对 Java bean 端点实现类使用 @BindingType 注释以启用 MTOM

  • 注释目标:类型
  • 属性:

- value

指示绑定标识 Web 地址。有效值为 javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDINGjavax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING javax.xml.ws.http.HTTPBinding.HTTP2HTTP_BINDING 缺省值为 javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING。(字 符串)

javax.xml.ws.RequestWrapper

@RequestWrapper 注释提供 JAXB 生成的请求包装器 bean、元素名称和名称空间,用于对在运行时使用的请求包装器 bean 进行序列化和反序列化。

Java 对象开始时,此元素用来解决 document literal 方式下的重载冲突。在这种情况下,只有 className 属性是必需的。

将此注释应用于客户机或服务器服务端点接口(SEI)上的方法,或者应用于 JavaBeans 端点的服务器端点实现类。

  • 注释目标:方法
  • 属性:

- localName

指定用于表示请求包装器的 XML 模式元素的局部名称。缺省值为在 javax.jws.WebMethod 注释中定义的 operationName。(字符串)

- targetNamespace

指定请求包装器方法的 XML 名称空间。缺省值为 SEI 的目标名称空间。(字符串)

- className

指定用于表示请求包装器的类的名称。(字符串)

javax.xml.ws.ResponseWrapper

@ResponseWrapper 注释提供 JAXB 生成的响应包装器 bean、元素名称和名称空间,用于对在运行时使用的响应包装器 bean 进行序列化和反序列化。

Java 对象开始时,此元素用来解决 document literal 方式下的重载冲突。在这种情况下,只有 className 属性是必需的。

将此注释应用于客户机或服务器服务端点接口(SEI)上的方法,或者应用于 JavaBeans 端点的服务器端点实现类。

  • 注释目标:方法
  • 属性:

- localName

指定用于表示请求包装器的 XML 模式元素的局部名称。缺省值为 operationName + ResponseoperationName 是在 javax.jws.WebMethod 注释中定义的。(字符串)

- targetNamespace

指定请求包装器方法的 XML 名称空间。缺省值为 SEI 的目标名称空间。(字符串)

- className

指定用于表示响应包装器的类的名称。(字符串)

javax.xml.ws.ServiceMode

@ServiceMode 注释指定服务提供者是需要对整个协议消息具有访问权还是只需对消息有效内容具有访问权。

要点:

仅支持在使用 @WebServiceProvider 注释来注释的类上使用 @ServiceMode 注释。

  • 注释目标:类型
  • 属性:

- value

指示提供者类是接受消息的有效内容 PAYLOAD 还是整个消息 MESSAGE。缺省值为 PAYLOAD。(字 符串)

javax.xml.ws.WebFault

@WebFault 注释将 WSDL 故障映射至 Java 异常。对从 WSDL 故障消息引用的全局元

分享到:
评论

相关推荐

    win2k下用winsock原始套接字抓包

    This file contains a summary of what you will find in each of the files that make up your WS232LIB application. WS232LIB.dsp This file (the project file) contains information at the project level ...

    基于wpf的excel制作类

    summary&gt; Excel操作代理 &lt; summary&gt; class ExcelAgent { private ApplicationClass app null; private Workbook wb null; private Worksheet ws null; private string filePath &quot;&quot;; ...

    c#仿vista风格窗体

    SetWindowLong(new HandleRef(form, form.Handle), -16, windowLong | WS_SYSMENU | WS_MINIMIZEBOX); //注意,这里是重点:WS_SYSMENU允许有系统菜单 WS_MINIMIZEBOX:可以最大最小化 //这两个参数是上面那个类里...

    wpf的Excel分类导出数据(Aspose)

    对学习wpf的朋友们有一定的帮助 /// &lt;summary&gt; /// 工参表分割类, 按区域进行对数据行进行分割 /// &lt;/summary&gt; public class AreaSplit { public event EventHandler&lt;StringEventArgs&gt; Opening; public event ...

    c# Excel 操作类

    /// &lt;summary&gt; /// 将内存中数据表格插入到Excel指定工作表的指定位置 /// &lt;/summary&gt; /// 数据表 /// &lt;param name="ws"&gt;工作表对象 /// 起始的X 列值 /// 起始的Y 行值 /// &lt;returns&gt;&lt;c&gt;true操作成功&lt;c&gt;...

    去掉Windows CE和 Pocket PC中和OK按钮

    public const UInt32 WS_NONAVDONEBUTTON = 0x00010000; /// &lt;summary&gt; /// 隐藏OK按钮 /// &lt;/summary&gt; /// &lt;param name="hWnd"&gt;&lt;/param&gt; public static void HideDoneButton(IntPtr hWnd) { SHDoneButton(hWnd, ...

    Manning.Spring.in.Action.4th.Edition.2014.11.epub

    15.5.2. Proxying JAX-WS services on the client side 15.6. Summary Chapter 16. Creating REST APIs with Spring MVC 16.1. Getting REST 16.1.1. The fundamentals of REST 16.1.2. How Spring supports REST ...

    VBA-Challenge

    Public Sub StockData1()'遍历所有表'--------------------------------------- -----将WS作为ActiveWorkbook.Worksheets WS.Activate'中的每个WS的工作表调暗WS =确定最后一行Lastrow = WS.Cells(Rows.Count,1...

    Microsoft SharePoint 2010 Developer Reference

    Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 2 Data Foundation 31 Lists of Items and Contents . 31 Site Columns 46 ...

    C#控制Excel Sheet使其自适应页宽与列宽的方法

    本文实例讲述了C#控制Excel Sheet使其自适应页宽与列宽的方法。分享给大家供大家参考,具体如下: .../// &lt;param name=ws&gt; private void WorkSheetPageSet(Microsoft.Office.Interop.Excel.Application

    C#简单的通用基础字典实现方法

    本文实例讲述了C#简单的通用基础字典实现方法。...using Alif.Alif_WSAPI; using System.Data; using System.Windows.Forms; namespace Alif.AlifForm.CommClass {  /// &lt;summary&gt;  ///  /// &lt;/summary&gt;  public

    .NET Core in Action

    Summary .NET Core in Action shows .NET developers how to build professional software applications with .NET Core. Learn how to convert existing .NET code to work on multiple platforms or how to start...

    VS PInvoke插件 RedGate.PInvokeExtension VS平台调用插件 PInvoke.NET 最新 最全

    ws2_32 wtsapi32 xolehlp xpsprint Smart Device Functions: aygshell coredll ipaqutil rapi Glossary distributed computing LibHolocaust Marshaling Marshalling Marshalling PInvoke test pinvoke ...

    最新C3550 IOS EMI

    A summary of U.S. laws governing Cisco cryptographic products may be found at: http://www.cisco.com/wwl/export/crypto/tool/stqrg.html If you require further assistance please contact us by sending ...

    C#实现控制摄像头的类

    /// &lt;summary&gt; /// 一个控制摄像头的类 /// &lt;/summary&gt; public class Pick { private const int WM_USER = 0x400; private const int WS_CHILD = 0x40000000; private const int WS_VISIBLE = 0x10000000; ...

    C#创建windows系统用户的方法

    本文实例讲述了C#创建.../// &lt;summary&gt; /// method to create a new local Windows user account /// &lt;/summary&gt; /// &lt;param name=username&gt;Username of the new account /// &lt;param name=password&gt;Password of the ne

    C#使用FolderBrowserDialog类实现选择打开文件夹方法详解

    1.在C#中使用FolderBrowserDialog类,就可以实现选择文件夹的功能,并将所选择的的文件夹路径记录下来。 (1).首先先引入命名空间System.... /// &lt;/summary&gt; [STAThread] static void Main() { Application.Ena

    C#通过windows注册表获取软件清单的方法

    本文实例讲述了C#通过windows注册表获取软件清单的方法。分享给大家供大家参考。具体如下: foreach (string SoftwareName in Object..../// &lt;summary&gt; /// Windows系统获取软件列表 /// &lt;/summary&gt; /// &lt;returns&gt;Str

    使用windows控制台调试服务的方法

    将Program类的删除,将里面的静态类Main修改后放入服务类中: 代码如下:partial class Server1 : ... } /// &lt;summary&gt; /// 应用程序的主入口点。 /// &lt;/summary&gt; static void Main(string[] args) {  Server1 s

    Werner 综合征蛋白:更新

    Summary Progeria and progeroid syndromes are characterized by the earlier onset of complex senescent phenotypes. WRN was originally identified as a gene responsible for Werner syndrome (WS; ``Progeria...

Global site tag (gtag.js) - Google Analytics