cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache CXF Documentation > Developing a Service
Date Mon, 07 Feb 2011 22:15:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2036/9/1/_/styles/combined.css?spaceKey=CXF20DOC&amp;forWysiwyg=true" type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CXF20DOC/Developing+a+Service">Developing a Service</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~mazzag">Glen Mazza</a>
    </h4>
        <div id="versionComment">
        <b>Comment:</b>
        Remove "Example" texts from examples (makes more Docbook-friendly)<br />
    </div>
        <br/>
                         <h4>Changes (22)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >h4. Example <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >For example, an implementation class for a service that defined the operations {{sayHi}} and {{greetMe}} may look like <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">[#Example1]</span> <span class="diff-added-words"style="background-color: #dfd;">the following:</span> <br></td></tr>
            <tr><td class="diff-unchanged" > <br>{anchor:Example1} <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">{code:title=<span class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">Example 1: </span>Implementation</span> of the Greeter Service} <br></td></tr>
            <tr><td class="diff-unchanged" >package demo.hw.server; <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >JAX-WS defines an annotation that allows you to specify methods that are not exposed as part of a service. However, the best practice is to leave such methods out of the SEI. <br>{tip} <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">[#Example2]</span> <span class="diff-added-words"style="background-color: #dfd;">The below</span> shows a simple SEI for a stock updating service. <br></td></tr>
            <tr><td class="diff-unchanged" > <br>{anchor:Example2} <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">{code:title=<span class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">Example2:</span>Simple</span> SEI} <br></td></tr>
            <tr><td class="diff-unchanged" >package org.apache.cxf; <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >Because the SEI is a standard Java interface, the class that implements it is just a standard Java class. If you started with a Java class you will need to modify it to implement the interface. If you are starting fresh, the implementation class will need to implement the SEI. <br> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">[#Example3] shows a class for implementing the interface in [#Example2]. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">The below shows a class for implementing the above interface. <br></td></tr>
            <tr><td class="diff-unchanged" > <br>{anchor:Example3} <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">{code:title=<span class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">Example3:</span>Implementation</span> for SEI} <br></td></tr>
            <tr><td class="diff-unchanged" >package org.apache.cxf; <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >The SEI requires that you add the {{@WebService}} annotation. Since the SEI is the contract that defines the service, you should specify as much detail as you can about the service in the {{@WebService}} annotation&#39;s properties. <br> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">[#Example4] shows the interface defined in [#Example2] with the {{@WebService}} annotation. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">The code below shows the interface defined [above|#Example2] with the {{@WebService}} annotation. <br></td></tr>
            <tr><td class="diff-unchanged" > <br>{anchor:Example4} <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">{code:title=<span class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">Example4:</span>Interface</span> with the @WebService Annotation} <br></td></tr>
            <tr><td class="diff-unchanged" >package com.mycompany.demo; <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >} <br>{code} <br></td></tr>
            <tr><td class="diff-changed-lines" >The {{@WebService}} annotation <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">in [#Example4]</span> <span class="diff-added-words"style="background-color: #dfd;">[above|#Example4]</span> does the following: <br></td></tr>
            <tr><td class="diff-unchanged" ># Specifies that the value of the name attribute of the {{wsdl:portType}} element defining the service interface is {{quoteUpdater}}. <br># Specifies that the target namespace of the service is {{http://cxf.apache.org}}. <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br>{anchor:Example5} <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">{code:title=<span class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">Example5:</span>Annotated</span> Service Implementation Class} <br></td></tr>
            <tr><td class="diff-unchanged" >package org.apache.cxf; <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >| use | {{Use.LITERAL}} (default) \\  {{Use.ENCODED}} | Specifies how the data of the SOAP message is streamed. | <br>| parameterStyle | {{ParameterStyle.BARE}}\\  {{ParameterStyle.WRAPPED}} (default) | Specifies how the method parameters, which correspond to message parts in a WSDL contract, are placed into the SOAP message body. A parameter style of {{BARE}} means that each parameter is placed into the message body as a child element of the message root. A parameter style of {{WRAPPED}} means that all of the input parameters are wrapped into a single element on a request message and that all of the output parameters are wrapped into a single element in the response message. If you set the style to RPC you must use the {{WRAPPED}} parameter style. | <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">[#Example6] shows an SEI that uses rpc/literal SOAP messages. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">An SEI that uses rpc/literal SOAP messages is as follows: <br></td></tr>
            <tr><td class="diff-unchanged" > <br>{anchor:Example6} <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">{code:title=<span class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">Example6:</span>Specifying</span> an RPC/LITERAL SOAP Binding} <br></td></tr>
            <tr><td class="diff-unchanged" >package org.eric.demo; <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >h5. Example <br> <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">[#Example7]</span> <span class="diff-added-words"style="background-color: #dfd;">The below</span> shows an SEI whose methods are annotated. <br></td></tr>
            <tr><td class="diff-unchanged" > <br>{anchor:Example7} <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">{code:title=<span class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">Example7:</span>SEI</span> with Annotated Methods} <br></td></tr>
            <tr><td class="diff-unchanged" >package org.apache.cxf; <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >h5. Example <br> <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">[#Example8]</span> <span class="diff-added-words"style="background-color: #dfd;">The next example</span> shows an SEI that is fully annotated. <br></td></tr>
            <tr><td class="diff-unchanged" > <br>{anchor:Example8} <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">{code:title=<span class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">Example8:</span>Fully</span> Annotated SEI} <br></td></tr>
            <tr><td class="diff-unchanged" >package org.apache.cxf; <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >h4. Example <br> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">[#Example9] shows the WSDL contract generated for the SEI shown in [#Example8]. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">The next example shows the WSDL contract generated for the SEI shown [above|#Example8]: <br></td></tr>
            <tr><td class="diff-unchanged" > <br>{anchor:Example9} <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">{code:title=<span class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">Example9:</span>Generated</span> WSDL from an SEI} <br></td></tr>
            <tr><td class="diff-unchanged" >&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; <br>&lt;wsdl:definitions targetNamespace=&quot;http://demo.eric.org/&quot; <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <div>
<ul>
    <li><a href='#DevelopingaService-DevelopingaServiceusingJAXWS'>Developing a Service using JAX-WS</a></li>
<ul>
    <li><a href='#DevelopingaService-WSDLFirstDevelopment'>WSDL First Development</a></li>
<ul>
    <li><a href='#DevelopingaService-GeneratingtheStartingPointCode'>Generating the Starting Point Code</a></li>
<ul>
    <li><a href='#DevelopingaService-Runningwsdl2java'>Running wsdl2java</a></li>
    <li><a href='#DevelopingaService-Generatedcode'>Generated code</a></li>
</ul>
    <li><a href='#DevelopingaService-ImplementingtheService'>Implementing the Service</a></li>
<ul>
    <li><a href='#DevelopingaService-Generatingtheimplementationcode'>Generating the implementation code</a></li>
    <li><a href='#DevelopingaService-Generatedcode'>Generated code</a></li>
    <li><a href='#DevelopingaService-Implementtheoperation%27slogic'>Implement the operation's logic</a></li>
    <li><a href='#DevelopingaService-Example'>Example</a></li>
</ul>
</ul>
    <li><a href='#DevelopingaService-JavaFirstDevelopment'>Java First Development</a></li>
<ul>
    <li><a href='#DevelopingaService-CreatingtheSEI'>Creating the SEI</a></li>
<ul>
    <li><a href='#DevelopingaService-Writingtheinterface'>Writing the interface</a></li>
    <li><a href='#DevelopingaService-Implementingtheinterface'>Implementing the interface</a></li>
</ul>
    <li><a href='#DevelopingaService-AnnotatingtheCode'>Annotating the Code</a></li>
<ul>
    <li><a href='#DevelopingaService-RequiredAnnotations'>Required Annotations</a></li>
<ul>
    <li><a href='#DevelopingaService-The%7B%7B@WebService%7D%7Dannotation'>The <tt>@WebService</tt> annotation</a></li>
    <li><a href='#DevelopingaService-AnnotatingtheSEI'>Annotating the SEI</a></li>
    <li><a href='#DevelopingaService-Annotatingtheserviceimplementation'>Annotating the service implementation</a></li>
</ul>
    <li><a href='#DevelopingaService-OptionalAnnotations'>Optional Annotations</a></li>
<ul>
    <li><a href='#DevelopingaService-DefiningtheBindingPropertieswithAnnotations'>Defining the Binding Properties with Annotations</a></li>
    <li><a href='#DevelopingaService-The%7B%7B@SOAPBinding%7D%7Dannotation'>The <tt>@SOAPBinding</tt> annotation</a></li>
    <li><a href='#DevelopingaService-DefiningOperationPropertieswithAnnotations'>Defining Operation Properties with Annotations</a></li>
    <li><a href='#DevelopingaService-The%7B%7B@WebMethod%7D%7Dannotation'>The <tt>@WebMethod</tt> annotation</a></li>
    <li><a href='#DevelopingaService-The%7B%7B@RequestWrapper%7D%7Dannotation'>The <tt>@RequestWrapper</tt> annotation</a></li>
    <li><a href='#DevelopingaService-The%7B%7B@ResponseWrapper%7D%7Dannotation'>The <tt>@ResponseWrapper</tt> annotation</a></li>
    <li><a href='#DevelopingaService-The%7B%7B@WebFault%7D%7Dannotation'>The <tt>@WebFault</tt> annotation</a></li>
    <li><a href='#DevelopingaService-The%7B%7B@Oneway%7D%7Dannotation'>The <tt>@Oneway</tt> annotation</a></li>
    <li><a href='#DevelopingaService-Example'>Example</a></li>
    <li><a href='#DevelopingaService-DefiningParameterPropertieswithAnnotations'>Defining Parameter Properties with Annotations</a></li>
    <li><a href='#DevelopingaService-The%7B%7B@WebParam%7D%7Dannotation'>The <tt>@WebParam</tt> annotation</a></li>
    <li><a href='#DevelopingaService-The%7B%7B@WebResult%7D%7Dannotation'>The <tt>@WebResult</tt> annotation</a></li>
    <li><a href='#DevelopingaService-Example'>Example</a></li>
</ul>
</ul>
    <li><a href='#DevelopingaService-GeneratingWSDL'>Generating WSDL</a></li>
<ul>
    <li><a href='#DevelopingaService-Example'>Example</a></li>
</ul>
</ul>
</ul>
</ul></div>

<h1><a name="DevelopingaService-DevelopingaServiceusingJAXWS"></a>Developing a Service using JAX-WS</h1>

<p>You can develop a service using one of two approaches:</p>
<ul>
	<li>Start with a WSDL contract and generate Java objects to implement the service.</li>
	<li>Start with a Java object and service enable it using annotations.<br/>
For new development the preferred path is to design your services in WSDL and then generate the code to implement them. This approach enforces the concept that a service is an abstract entity that is implementation neutral. It also means you can spend more time working out the exact interface your service requires before you start coding.</li>
</ul>


<p>However, there are many cases where you may need to service enable an existing application. While JAX-WS eases the process, it does require that you make some changes to source code of your application. You will need to add annotations to the source. It also requires that you migrate your code to Java 5.0.</p>

<h2><a name="DevelopingaService-WSDLFirstDevelopment"></a>WSDL First Development</h2>

<p>Using the WSDL first model of service development, you start with a WSDL document that defines the service you wish to implement. This WSDL document could be obtained from another developer, a system architect, a UDDI registry, or you could write it yourself. The document must contain at least a fully specified logical interface before you can begin generating code from it.</p>

<p>Once you have a WSDL document, the process for developing a JAX-WS service is three steps:</p>
<ol>
	<li>Generate starting point code.</li>
	<li>Implement the service's operations.</li>
	<li>Publish the implemented service.</li>
</ol>


<h3><a name="DevelopingaService-GeneratingtheStartingPointCode"></a>Generating the Starting Point Code</h3>

<p>JAX-WS specifies a detailed mapping from a service defined in WSDL to the Java classes that will implement that service. The logical interface, defined by the <tt>wsdl:portType</tt> element, is mapped to a service endpoint interface (SEI). Any complex types defined in the WSDL are mapped into Java classes following the mapping defined by the Java Architecture for XML Binding (JAXB) specification. The endpoint defined by the <tt>wsdl:service</tt> element is also generated into a Java class that is used by consumers to access endpoints implementing the service.</p>

<p>The <b>wsdl2java</b> command automates the generation of this code. It also provides options for generating starting point code for your implementation and an ant based makefile to build the application. <b>wsdl2java</b> provides a number of arguments for controlling the generated code.</p>

<h4><a name="DevelopingaService-Runningwsdl2java"></a>Running wsdl2java</h4>

<p>You can generate the code needed to develop your service using the following command:<br/>
 wsdl2java &#45;ant &#45;impl &#45;server &#45;d <em>outputDir</em> myService.wsdl</p>

<p> The command does the following:</p>
<ul>
	<li>The <tt>&#45;ant</tt> argument generates a Ant makefile, called <tt>build.xml</tt>, for your application.</li>
	<li>The <tt>&#45;impl</tt> argument generates a shell implementation class for each portType element in the WSDL document.</li>
	<li>The <tt>&#45;server</tt> argument generates a simple <tt>main()</tt> to launch your service as a stand alone application.</li>
	<li>The <tt>&#45;d <em>outputDir</em></tt> argument tells <b>wsdl2java</b> to write the generated code to a directory called outputDir.</li>
	<li><tt>myService.wsdl</tt> is  the WSDL document from which code is generated.</li>
</ul>


<h4><a name="DevelopingaService-Generatedcode"></a>Generated code</h4>

<p><a href="#DevelopingaService-Table1">Table1</a> describes the files generated for creating a service.</p>

<p><a name="DevelopingaService-Table1"></a> <b>Table 1: Generated Classes for a Service</b></p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> File </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt><em>portTypeName</em>.java</tt> </td>
<td class='confluenceTd'> The SEI. This file contains the interface your service implements. You should not edit this file. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt><em>serviceName</em>.java</tt> </td>
<td class='confluenceTd'> The endpoint. This file contains the Java class your clients will use to make requests on the service. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt><em>portTypeName</em>Impl.java</tt> </td>
<td class='confluenceTd'> The skeleton implementation class. You will modify this file to implement your service. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt><em>portTypeName</em>_<em>portTypeName</em>ImplPort_Server.java</tt> </td>
<td class='confluenceTd'> A basic server <tt>main()</tt> that allows you to deploy your service as a stand alone process. </td>
</tr>
</tbody></table>
</div>


<h3><a name="DevelopingaService-ImplementingtheService"></a>Implementing the Service</h3>

<p>Once the starting point code is generated, you must provide the business logic for each of the operations defined in the service's interface.</p>

<h4><a name="DevelopingaService-Generatingtheimplementationcode"></a>Generating the implementation code</h4>

<p>You generate the implementation class for your service with <b>wsdl2java</b>'s <tt>&#45;impl</tt> flag.</p>
<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Tip</b><br />If your service's contract included any custom types defined in XML Schema, you will also need to ensure that the classes for the types are also generated and available.</td></tr></table></div>

<h4><a name="DevelopingaService-Generatedcode"></a>Generated code</h4>

<p>The service implementation code consists of two files:</p>
<ul>
	<li><tt><em>portTypeName</em>.java</tt> is the service interface(SEI) for the service.</li>
	<li><tt><em>portTypeName</em>Impl.java</tt> is the class you will use to implement the operations defined for the service.</li>
</ul>


<h4><a name="DevelopingaService-Implementtheoperation%27slogic"></a>Implement the operation's logic</h4>

<p>You provide the business logic for your service's operations by completing the stub methods in <tt><em>portTypeName</em>Impl.java</tt>. For the most part, you use standard Java to implement the business logic. If your service uses custom XML Schema types, you will need to use the generated classes for each type to manipulate them. There are also some CXF specific APIs that you can use to access some advanced features.</p>

<h4><a name="DevelopingaService-Example"></a>Example</h4>

<p>For example, an implementation class for a service that defined the operations <tt>sayHi</tt> and <tt>greetMe</tt> may look like the following:</p>

<p><a name="DevelopingaService-Example1"></a></p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Implementation of the Greeter Service</b></div><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">package</span> demo.hw.server;

<span class="code-keyword">import</span> org.apache.hello_world_soap_http.Greeter;

@javax.jws.WebService(portName = <span class="code-quote">"SoapPort"</span>, serviceName = <span class="code-quote">"SOAPService"</span>,
 targetNamespace = <span class="code-quote">"http:<span class="code-comment">//apache.org/hello_world_soap_http"</span>,
</span> endpointInterface = <span class="code-quote">"org.apache.hello_world_soap_http.Greeter"</span>)

<span class="code-keyword">public</span> class GreeterImpl <span class="code-keyword">implements</span> Greeter {

 <span class="code-keyword">public</span> <span class="code-object">String</span> greetMe(<span class="code-object">String</span> me)
{
        <span class="code-object">System</span>.out.println(<span class="code-quote">"Executing operation greetMe"</span>);
        <span class="code-object">System</span>.out.println(<span class="code-quote">"Message received: "</span> + me + <span class="code-quote">"\n"</span>);
        <span class="code-keyword">return</span> <span class="code-quote">"Hello "</span> + me;
     }

 <span class="code-keyword">public</span> <span class="code-object">String</span> sayHi()
{
        <span class="code-object">System</span>.out.println(<span class="code-quote">"Executing operation sayHi\n"</span>);
        <span class="code-keyword">return</span> <span class="code-quote">"Bonjour"</span>;
     }
}
</pre>
</div></div>

<h2><a name="DevelopingaService-JavaFirstDevelopment"></a>Java First Development</h2>

<p>To create a service starting from Java you need to do the following:</p>
<ol>
	<li>Create a Service Endpoint Interface (SEI) that defines the methods you wish to expose as a service.
<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Tip</b><br />You can work directly from a Java class, but working from an interface is the recommended approach. Interfaces are better for sharing with the developers who will be responsible for developing the applications consuming your service. The interface is smaller and does not provide any of the service's implementation details.</td></tr></table></div></li>
	<li>Add the required annotations to your code.</li>
	<li>Generate the WSDL contract for your service.
<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Tip</b><br />If you intend to use the SEI as the service's contract, it is not necessary to generate a WSDL contract</td></tr></table></div></li>
	<li>Publish the service.</li>
</ol>


<h3><a name="DevelopingaService-CreatingtheSEI"></a>Creating the SEI</h3>

<p>The service endpoint interface (SEI) is the piece of Java code that is shared between a service and the consumers that make requests on it. When starting with a WSDL contract, the SEI is generated by the code generators. However, when starting from Java, it is the up to a developer to create the SEI.</p>

<p>There are two basic patterns for creating an SEI:</p>
<ul>
	<li>Green field development
<br class="atl-forced-newline" />
You are developing a new service from the ground up. When starting fresh, it is best to start by creating the SEI first. You can then distribute the SEI to any developers that are responsible for implementing the services and consumers that use the SEI.
<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Note</b><br />The recommended way to do green field service development is to start by creating a WSDL contract that defines the service and its interfaces.</td></tr></table></div></li>
	<li>Service enablement
<br class="atl-forced-newline" />
In this pattern, you typically have an existing set of functionality that is implemented as a Java class and you want to service enable it. This means that you will need to do two things:
	<ol>
		<li>Create an SEI that contains <b>only</b> the operations that are going to be exposed as part of the service.</li>
		<li>Modify the existing Java class so that it implements the SEI.
<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Note</b><br />You can add the JAX-WS annotations to a Java class, but that is not recommended.</td></tr></table></div></li>
	</ol>
	</li>
</ul>


<h4><a name="DevelopingaService-Writingtheinterface"></a>Writing the interface</h4>

<p>The SEI is a standard Java interface. It defines a set of methods that a class will implement. It can also define a number of member fields and constants to which the implementing class has access.</p>

<p>In the case of an SEI the methods defined are intended to be mapped to operations exposed by a service. The SEI corresponds to a <tt>wsdl:portType</tt> element. The methods defined by the SEI correspond to <tt>wsdl:operation</tt> elements in the <tt>wsdl:portType</tt> element.</p>
<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Tip</b><br />JAX-WS defines an annotation that allows you to specify methods that are not exposed as part of a service. However, the best practice is to leave such methods out of the SEI.</td></tr></table></div>
<p>The below shows a simple SEI for a stock updating service.</p>

<p><a name="DevelopingaService-Example2"></a></p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Simple SEI</b></div><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">package</span> org.apache.cxf;

<span class="code-keyword">public</span> <span class="code-keyword">interface</span> QuoteReporter
{
  <span class="code-keyword">public</span> Quote getQuote(<span class="code-object">String</span> ticker);
}
</pre>
</div></div>

<h4><a name="DevelopingaService-Implementingtheinterface"></a>Implementing the interface</h4>

<p>Because the SEI is a standard Java interface, the class that implements it is just a standard Java class. If you started with a Java class you will need to modify it to implement the interface. If you are starting fresh, the implementation class will need to implement the SEI.</p>

<p>The below shows a class for implementing the above interface.</p>

<p><a name="DevelopingaService-Example3"></a></p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Implementation for SEI</b></div><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">package</span> org.apache.cxf;

<span class="code-keyword">import</span> java.util.*;

<span class="code-keyword">public</span> class StockQuoteReporter <span class="code-keyword">implements</span> QuoteReporter
{
  ...
<span class="code-keyword">public</span> Quote getQuote(<span class="code-object">String</span> ticker)
  {
    Quote retVal = <span class="code-keyword">new</span> Quote();
    retVal.setID(ticker);
    retVal.setVal(Board.check(ticker));[1]
    Date retDate = <span class="code-keyword">new</span> Date();
    retVal.setTime(retDate.toString());
    <span class="code-keyword">return</span>(retVal);
  }
}
</pre>
</div></div>

<h3><a name="DevelopingaService-AnnotatingtheCode"></a>Annotating the Code</h3>

<p>JAX-WS relies on the annotation feature of Java 5. The JAX-WS annotations are used to specify the metadata used to map the SEI to a fully specified service definition. Among the information provided in the annotations are the following:</p>
<ul>
	<li>The target namespace for the service.</li>
	<li>The name of the class used to hold the request message.</li>
	<li>The name of the class used to hold the response message.</li>
	<li>If an operation is a one way operation.</li>
	<li>The binding style the service uses.</li>
	<li>The name of the class used for any custom exceptions.</li>
	<li>The namespaces under which the types used by the service are defined.
<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Tip</b><br />Most of the annotations have sensible defaults and do not need to be specified. However, the more information you provide in the annotations, the better defined your service definition. A solid service definition increases the likely hood that all parts of a distributed application will work together.</td></tr></table></div></li>
</ul>


<h4><a name="DevelopingaService-RequiredAnnotations"></a>Required Annotations</h4>

<p>In order to create a service from Java code you are only required to add one annotation to your code. You must add the <tt>@WebService()</tt> annotation on both the SEI and the implementation class.</p>

<h5><a name="DevelopingaService-The%7B%7B@WebService%7D%7Dannotation"></a>The <tt>@WebService</tt> annotation</h5>

<p>The <tt>@WebService</tt> annotation is defined by the <tt>javax.jws.WebService</tt> interface and it is placed on an interface or a class that is intended to be used as a service. <tt>@WebService</tt> has the following properties:</p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Property </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> name </td>
<td class='confluenceTd'> Specifies the name of the service interface. This property is mapped to the name attribute of the <tt>wsdl:portType</tt> element that defines the service's interface in a WSDL contract. The default is to append <tt>PortType</tt> to the name of the implementation class. </td>
</tr>
<tr>
<td class='confluenceTd'> targetNamespace </td>
<td class='confluenceTd'> Specifies the target namespace under which the service is defined. If this property is not specified, the target namespace is derived from the package name. </td>
</tr>
<tr>
<td class='confluenceTd'> serviceName </td>
<td class='confluenceTd'> Specifies the name of the published service. This property is mapped to the <tt>name</tt> attribute of the <tt>wsdl:service</tt> element that defines the published service. The default is to use the name of the service's implementation class.  <b>Note:</b> Not allowed on the SEI </td>
</tr>
<tr>
<td class='confluenceTd'> wsdlLocation </td>
<td class='confluenceTd'> Specifies the URI at which the service's WSDL contract is stored. The default is the URI at which the service is deployed. </td>
</tr>
<tr>
<td class='confluenceTd'> endpointInterface </td>
<td class='confluenceTd'> Specifies the full name of the SEI that the implementation class implements. This property is only used when the attribute is used on a service implementation class. <b>Note:</b> Not allowed on the SEI </td>
</tr>
<tr>
<td class='confluenceTd'> portName </td>
<td class='confluenceTd'> Specifies the name of the endpoint at which the service is published. This property is mapped to the <tt>name</tt> attribute of the <tt>wsdl:port</tt> element that specifies the endpoint details for a published service. The default is the append <tt>Port</tt> to the name of the service's implementation class. <b>Note:</b> Not allowed on the SEI </td>
</tr>
</tbody></table>
</div>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Tip</b><br />You do not need to provide values for any of the <tt>@WebService</tt> annotation's properties. However, it is recommended that you provide as much information as you can.</td></tr></table></div>

<h5><a name="DevelopingaService-AnnotatingtheSEI"></a>Annotating the SEI</h5>

<p>The SEI requires that you add the <tt>@WebService</tt> annotation. Since the SEI is the contract that defines the service, you should specify as much detail as you can about the service in the <tt>@WebService</tt> annotation's properties.</p>

<p>The code below shows the interface defined <a href="#DevelopingaService-Example2">above</a> with the <tt>@WebService</tt> annotation.</p>

<p><a name="DevelopingaService-Example4"></a></p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Interface with the @WebService Annotation</b></div><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">package</span> com.mycompany.demo;

<span class="code-keyword">import</span> javax.jws.*;

@WebService(name=<span class="code-quote">"quoteUpdater"</span>,
            targetNamespace=<span class="code-quote">"http:<span class="code-comment">//cxf.apache.org"</span>,
</span>            wsdlLocation=<span class="code-quote">"http:<span class="code-comment">//somewhere.com/quoteExampleService?wsdl"</span>)
</span><span class="code-keyword">public</span> <span class="code-keyword">interface</span> QuoteReporter
{
  <span class="code-keyword">public</span> Quote getQuote(@WebParam(name=<span class="code-quote">"ticker"</span>) <span class="code-object">String</span> ticker);
}
</pre>
</div></div>
<p>The <tt>@WebService</tt> annotation <a href="#DevelopingaService-Example4">above</a> does the following:</p>
<ol>
	<li>Specifies that the value of the name attribute of the <tt>wsdl:portType</tt> element defining the service interface is <tt>quoteUpdater</tt>.</li>
	<li>Specifies that the target namespace of the service is <tt><a href="http://cxf.apache.org" class="external-link" rel="nofollow">http://cxf.apache.org</a></tt>.</li>
	<li>Specifies that the service will use the pre-defined WSDL contract which is published at <tt><a href="http://somewhere.com/quoteExampleService?wsdl" class="external-link" rel="nofollow">http://somewhere.com/quoteExampleService?wsdl</a></tt>.</li>
</ol>


<p>The @WebParam annotation is necessary as java interfaces do not store the Parameter name in the .class file. So if you leave out the annotation your parameter will be named arg0.</p>

<h5><a name="DevelopingaService-Annotatingtheserviceimplementation"></a>Annotating the service implementation</h5>

<p>In addition to annotating the SEI with the <tt>@WebService</tt> annotation, you also have to annotate the service implementation class with the <tt>@WebService</tt> annotation. When adding the annotation to the service implementation class you only need to specify the <tt>endpointInterface</tt> property. As shown in <a href="#DevelopingaService-Example5">Example5</a> the property needs to be set to the full name of the SEI.</p>

<p><a name="DevelopingaService-Example5"></a></p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Annotated Service Implementation Class</b></div><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">package</span> org.apache.cxf;

<span class="code-keyword">import</span> javax.jws.*;

@WebService(endpointInterface=<span class="code-quote">"org.apache.cxf.quoteReporter"</span>,
            targetNamespace=<span class="code-quote">"http:<span class="code-comment">//cxf.apache.org"</span>,
</span>            portName=<span class="code-quote">"StockQuotePort"</span>,
            serviceName=<span class="code-quote">"StockQuoteReporter"</span>,
            )
<span class="code-keyword">public</span> class StockQuoteReporter <span class="code-keyword">implements</span> QuoteReporter
{
<span class="code-keyword">public</span> Quote getQuote(<span class="code-object">String</span> ticker)
  {
  ...
  }
}
</pre>
</div></div>

<h4><a name="DevelopingaService-OptionalAnnotations"></a>Optional Annotations</h4>

<p>While the <tt>@WebService</tt> annotation is sufficient for service enabling a Java interface or a Java class, it does not provide a lot of information about how the service will be exposed as an endpoint. The JAX-WS programming model uses a number of optional annotations for adding details about your service, such as the binding it uses, to the Java code. You add these annotations to the service's SEI.</p>
<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Tip</b><br />The more details you provide in the SEIthe easier it will be for developers to implement applications that can use the functionality it defines. It will also provide for better generated WSDL contracts.</td></tr></table></div>

<h5><a name="DevelopingaService-DefiningtheBindingPropertieswithAnnotations"></a>Defining the Binding Properties with Annotations</h5>

<p>If you are using a SOAP binding for your service, you can use JAX-WS annotations to specify a number of the bindings properties. These properties correspond directly to the properties you can specify in a service's WSDL contract.</p>

<h5><a name="DevelopingaService-The%7B%7B@SOAPBinding%7D%7Dannotation"></a>The <tt>@SOAPBinding</tt> annotation</h5>

<p>The <tt>@SOAPBinding</tt> annotation is defined by the <tt>javax.jws.soap.SOAPBinding</tt> interface. It provides details about the SOAP binding used by the service when it is deployed. If the <tt>@SOAPBinding</tt> annotation is not specified, a service is published using a wrapped doc/literal SOAP binding.</p>

<p>You can put the <tt>@SOAPBinding</tt> annotation on the SEI and any of the SEI's methods. When it is used on a method, setting of the method's <tt>@SOAPBinding</tt> annotation take precedent.</p>

<p>The following table shows the properties for the @SOAPBinding annotation.</p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Property </th>
<th class='confluenceTh'> Values </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> style </td>
<td class='confluenceTd'> <tt>Style.DOCUMENT</tt> (default) <br class="atl-forced-newline" />  <tt>Style.RPC</tt> </td>
<td class='confluenceTd'> Specifies the style of the SOAP message. If <tt>RPC</tt> style is specified, each message part within the SOAP body is a parameter or return value and will appear inside a wrapper element within the <tt>soap:body</tt> element. The message parts within the wrapper element correspond to operation parameters and must appear in the same order as the parameters in the operation. If <tt>DOCUMENT</tt> style is specified, the contents of the SOAP body must be a valid XML document, but its form is not as tightly constrained. </td>
</tr>
<tr>
<td class='confluenceTd'> use </td>
<td class='confluenceTd'> <tt>Use.LITERAL</tt> (default) <br class="atl-forced-newline" />  <tt>Use.ENCODED</tt> </td>
<td class='confluenceTd'> Specifies how the data of the SOAP message is streamed. </td>
</tr>
<tr>
<td class='confluenceTd'> parameterStyle </td>
<td class='confluenceTd'> <tt>ParameterStyle.BARE</tt><br class="atl-forced-newline" />  <tt>ParameterStyle.WRAPPED</tt> (default) </td>
<td class='confluenceTd'> Specifies how the method parameters, which correspond to message parts in a WSDL contract, are placed into the SOAP message body. A parameter style of <tt>BARE</tt> means that each parameter is placed into the message body as a child element of the message root. A parameter style of <tt>WRAPPED</tt> means that all of the input parameters are wrapped into a single element on a request message and that all of the output parameters are wrapped into a single element in the response message. If you set the style to RPC you must use the <tt>WRAPPED</tt> parameter style. </td>
</tr>
</tbody></table>
</div>

<p>An SEI that uses rpc/literal SOAP messages is as follows:</p>

<p><a name="DevelopingaService-Example6"></a></p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Specifying an RPC/LITERAL SOAP Binding</b></div><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">package</span> org.eric.demo;

<span class="code-keyword">import</span> javax.jws.*;
<span class="code-keyword">import</span> javax.jws.soap.*;
<span class="code-keyword">import</span> javax.jws.soap.SOAPBinding.*;

@WebService(name=<span class="code-quote">"quoteReporter"</span>)
@SOAPBinding(style=Style.RPC, use=Use.LITERAL)
<span class="code-keyword">public</span> <span class="code-keyword">interface</span> QuoteReporter
{
  ...
}
</pre>
</div></div>

<h5><a name="DevelopingaService-DefiningOperationPropertieswithAnnotations"></a>Defining Operation Properties with Annotations</h5>

<p>When the runtime maps your Java method definitions into XML operation definitions it fills in details such as:</p>
<ul>
	<li>what the exchanged messages look like in XML.</li>
	<li>if the message can be optimized as a one way message.</li>
	<li>the namespaces where the messages are defined.</li>
</ul>


<h5><a name="DevelopingaService-The%7B%7B@WebMethod%7D%7Dannotation"></a>The <tt>@WebMethod</tt> annotation</h5>

<p> The <tt>@WebMethod</tt> annotation is defined by the <tt>javax.jws.WebMethod</tt> interface. It is placed on the methods in the SEI. The <tt>@WebMethod</tt> annotation provides the information that is normally represented in the <tt>wsdl:operation</tt> element describing the operation to which the method is associated.</p>

<p>The following table describes the properties of the <tt>@WebMethod</tt> annotation.</p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Property </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> operationName </td>
<td class='confluenceTd'> Specifies the value of the associated <tt>wsdl:operation</tt> element's name. The default value is the name of the method. </td>
</tr>
<tr>
<td class='confluenceTd'> action </td>
<td class='confluenceTd'> Specifies the value of the <tt>soapAction</tt> attribute of the <tt>soap:operation</tt> element generated for the method. The default value is an empty string. </td>
</tr>
<tr>
<td class='confluenceTd'> exclude </td>
<td class='confluenceTd'> Specifies if the method should be excluded from the service interface. The default is <tt>false</tt>. </td>
</tr>
</tbody></table>
</div>


<h5><a name="DevelopingaService-The%7B%7B@RequestWrapper%7D%7Dannotation"></a>The <tt>@RequestWrapper</tt> annotation</h5>

<p> The <tt>@RequestWrapper</tt> annotation is defined by the <tt>javax.xml.ws.RequestWrapper</tt> interface. It is placed on the methods in the SEI. As the name implies, <tt>@RequestWrapper</tt> specifies the Java class that implements the wrapper bean for the method parameters that are included in the request message sent in a remote invocation. It is also used to specify the element names, and namespaces, used by the runtime when marshalling and unmarshalling the request messages.</p>

<p>The following table describes the properties of the @RequestWrapper annotation.</p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Property </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> localName </td>
<td class='confluenceTd'> Specifies the local name of the wrapper element in the XML representation of the request message. The default value is the name of the method or the value of the <tt>@WebMethod</tt> annotation's <tt>operationName</tt> property. </td>
</tr>
<tr>
<td class='confluenceTd'> targetNamespace </td>
<td class='confluenceTd'> Specifies the namespace under which the XML wrapper element is defined. The default value is the target namespace of the SEI. </td>
</tr>
<tr>
<td class='confluenceTd'> className </td>
<td class='confluenceTd'> Specifies the full name of the Java class that implements the wrapper element. </td>
</tr>
</tbody></table>
</div>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Tip</b><br />Only the <tt>className</tt> property is required.</td></tr></table></div>

<h5><a name="DevelopingaService-The%7B%7B@ResponseWrapper%7D%7Dannotation"></a>The <tt>@ResponseWrapper</tt> annotation</h5>

<p>The <tt>@ResponseWrapper</tt> annotation is defined by the <tt>javax.xml.ws.ResponseWrapper</tt> interface. It is placed on the methods in the SEI. As the name implies, <tt>@ResponseWrapper</tt> specifies the Java class that implements the wrapper bean for the method parameters that are included in the response message sent in a remote invocation. It is also used to specify the element names, and namespaces, used by the runtime when marshalling and unmarshalling the response messages.</p>

<p>The following table describes the properties of the <tt>@ResponseWrapper</tt> annotation.</p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Property </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> localName </td>
<td class='confluenceTd'> Specifies the local name of the wrapper element in the XML representation of the response message. The default value is the name of the method with <tt>Response</tt> appended or the value of the <tt>@WebMethod</tt> annotation's <tt>operationName</tt> property with <tt>Response</tt> appended. </td>
</tr>
<tr>
<td class='confluenceTd'> targetNamespace </td>
<td class='confluenceTd'> Specifies the namespace under which the XML wrapper element is defined. The default value is the target namespace of the SEI. </td>
</tr>
<tr>
<td class='confluenceTd'> className </td>
<td class='confluenceTd'> Specifies the full name of the Java class that implements the wrapper element. </td>
</tr>
</tbody></table>
</div>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Tip</b><br />Only the <tt>className</tt> property is required.</td></tr></table></div>

<h5><a name="DevelopingaService-The%7B%7B@WebFault%7D%7Dannotation"></a>The <tt>@WebFault</tt> annotation</h5>

<p>The <tt>@WebFault</tt> annotation is defined by the <tt>javax.xml.ws.WebFault</tt> interface. It is placed on exceptions that are thrown by your SEI. The <tt>@WebFault</tt> annotation is used to map the Java exception to a <tt>wsdl:fault</tt> element. This information is used to marshall the exceptions into a representation that can be processed by both the service and its consumers.</p>

<p>The following table describes the properties of the <tt>@WebFault</tt> annotation.</p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Property </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> name </td>
<td class='confluenceTd'> Specifies the local name of the fault element. </td>
</tr>
<tr>
<td class='confluenceTd'> targetNamespace </td>
<td class='confluenceTd'> Specifies the namespace under which the fault element is defined. The default value is the target namespace of the SEI. </td>
</tr>
<tr>
<td class='confluenceTd'> faultName </td>
<td class='confluenceTd'> Specifies the full name of the Java class that implements the exception. </td>
</tr>
</tbody></table>
</div>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Important</b><br />The <tt>name</tt> property is required.<br/>
FixMe: <tt>faultName</tt> is defined as <tt>beanName</tt> by the Sun Java EE 5 SDK at <a href="http://java.sun.com/javaee/5/docs/api/javax/xml/ws/WebFault.html" class="external-link" rel="nofollow">http://java.sun.com/javaee/5/docs/api/javax/xml/ws/WebFault.html</a>.</td></tr></table></div>

<h5><a name="DevelopingaService-The%7B%7B@Oneway%7D%7Dannotation"></a>The <tt>@Oneway</tt> annotation</h5>

<p>The <tt>@Oneway</tt> annotation is defined by the <tt>javax.jws.Oneway</tt> interface. It is placed on the methods in the SEI that will not require a response from the service. The <tt>@Oneway</tt> annotation tells the run time that it can optimize the execution of the method by not waiting for a response and not reserving any resources to process a response.</p>

<h5><a name="DevelopingaService-Example"></a>Example</h5>

<p>The below shows an SEI whose methods are annotated.</p>

<p><a name="DevelopingaService-Example7"></a></p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>SEI with Annotated Methods</b></div><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">package</span> org.apache.cxf;

<span class="code-keyword">import</span> javax.jws.*;
<span class="code-keyword">import</span> javax.xml.ws.*;

@WebService(name=<span class="code-quote">"quoteReporter"</span>)
<span class="code-keyword">public</span> <span class="code-keyword">interface</span> QuoteReporter
{
  @WebMethod(operationName=<span class="code-quote">"getStockQuote"</span>)
  @RequestWrapper(targetNamespace=<span class="code-quote">"http:<span class="code-comment">//demo.mycompany.com/types"</span>,
</span>                  className=<span class="code-quote">"java.lang.<span class="code-object">String</span>"</span>)
  @ResponseWrapper(targetNamespace=<span class="code-quote">"http:<span class="code-comment">//demo.mycompany.com/types"</span>,
</span>                   className=<span class="code-quote">"org.eric.demo.Quote"</span>)
  <span class="code-keyword">public</span> Quote getQuote(<span class="code-object">String</span> ticker);
}
</pre>
</div></div>

<h5><a name="DevelopingaService-DefiningParameterPropertieswithAnnotations"></a>Defining Parameter Properties with Annotations</h5>

<p>The method parameters in the SEI coresspond to the <tt>wsdl:message</tt> elements and their <tt>wsdl:part</tt> elements. JAX-WS provides annotations that allow you to describe the <tt>wsdl:part</tt> elements that are generated for the method parameters.</p>

<h5><a name="DevelopingaService-The%7B%7B@WebParam%7D%7Dannotation"></a>The <tt>@WebParam</tt> annotation</h5>

<p>The <tt>@WebParam</tt> annotation is defined by the <tt>javax.jws.WebParam</tt> interface. It is placed on the parameters on the methods defined in the SEI. The <tt>@WebParam</tt> annotation allows you to specify the direction of the parameter, if the parameter will be placed in the SOAP header, and other properties of the generated <tt>wsdl:part</tt>.</p>

<p>The following table describes the properties of the <tt>@WebParam</tt> annotation.</p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Property </th>
<th class='confluenceTh'> Values </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> name </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> Specifies the name of the parameter as it appears in the WSDL. For RPC bindings, this is name of the <tt>wsdl:part</tt> representing the parameter. For document bindings, this is the local name of the XML element representing the parameter. Per the JAX-WS specification, the default is <em>argN</em>, where <em>N</em> is replaced with the zero-based argument index (i.e., <em>arg0</em>, <em>arg1</em>, etc.) </td>
</tr>
<tr>
<td class='confluenceTd'> targetNamespace </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> Specifies the namespace for the parameter. It is only used with document bindings where the parameter maps to an XML element. The defaults is to use the service's namespace. </td>
</tr>
<tr>
<td class='confluenceTd'> mode </td>
<td class='confluenceTd'> <tt>Mode.IN</tt> (default) <br class="atl-forced-newline" />  <tt>Mode.OUT</tt><br class="atl-forced-newline" />  <tt>Mode.INOUT</tt> </td>
<td class='confluenceTd'> Specifies the direction of the parameter. </td>
</tr>
<tr>
<td class='confluenceTd'> header </td>
<td class='confluenceTd'> <tt>false</tt> (default) <br class="atl-forced-newline" />  <tt>true</tt> </td>
<td class='confluenceTd'> Specifies if the parameter is passed as part of the SOAP header. </td>
</tr>
<tr>
<td class='confluenceTd'> partName </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> Specifies the value of the name attribute of the <tt>wsdl:part</tt> element for the parameter when the binding is document. </td>
</tr>
</tbody></table>
</div>


<h5><a name="DevelopingaService-The%7B%7B@WebResult%7D%7Dannotation"></a>The <tt>@WebResult</tt> annotation</h5>

<p>The <tt>@WebResult</tt> annotation is defined by the <tt>javax.jws.WebResult</tt> interface. It is placed on the methods defined in the SEI. The <tt>@WebResult</tt> annotation allows you to specify the properties of the generated <tt>wsdl:part</tt> that is generated for the method's return value.</p>

<p>The following table describes the properties of the <tt>@WebResult</tt> annotation.</p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Property </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> name </td>
<td class='confluenceTd'> Specifies the name of the return value as it appears in the WSDL. For RPC bindings, this is name of the <tt>wsdl:part</tt> representing the return value. For document bindings, this is the local name of the XML element representing the return value. The default value is return. </td>
</tr>
<tr>
<td class='confluenceTd'> targetNamespace </td>
<td class='confluenceTd'> Specifies the namespace for the return value. It is only used with document bindings where the return value maps to an XML element. The defaults is to use the service's namespace. </td>
</tr>
<tr>
<td class='confluenceTd'> header </td>
<td class='confluenceTd'> Specifies if the return value is passed as part of the SOAP header. </td>
</tr>
<tr>
<td class='confluenceTd'> partName </td>
<td class='confluenceTd'> Specifies the value of the name attribute of the <tt>wsdl:part</tt> element for the return value when the binding is document. </td>
</tr>
</tbody></table>
</div>


<h5><a name="DevelopingaService-Example"></a>Example</h5>

<p>The next example shows an SEI that is fully annotated.</p>

<p><a name="DevelopingaService-Example8"></a></p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Fully Annotated SEI</b></div><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">package</span> org.apache.cxf;

<span class="code-keyword">import</span> javax.jws.*;
<span class="code-keyword">import</span> javax.xml.ws.*;
<span class="code-keyword">import</span> javax.jws.soap.*;
<span class="code-keyword">import</span> javax.jws.soap.SOAPBinding.*;
<span class="code-keyword">import</span> javax.jws.WebParam.*;

@WebService(name=<span class="code-quote">"quoteReporter"</span>)
@SOAPBinding(style=Style.RPC, use=Use.LITERAL)
<span class="code-keyword">public</span> <span class="code-keyword">interface</span> QuoteReporter
{
  @WebMethod(operationName=<span class="code-quote">"getStockQuote"</span>)
  @RequestWrapper(targetNamespace=<span class="code-quote">"http:<span class="code-comment">//demo.mycompany.com/types"</span>,
</span>                  className=<span class="code-quote">"java.lang.<span class="code-object">String</span>"</span>)
  @ResponseWrapper(targetNamespace=<span class="code-quote">"http:<span class="code-comment">//demo.mycompany.com/types"</span>,
</span>                   className=<span class="code-quote">"org.eric.demo.Quote"</span>)
  @WebResult(targetNamespace=<span class="code-quote">"http:<span class="code-comment">//demo.mycompany.com/types"</span>,
</span>             name=<span class="code-quote">"updatedQuote"</span>)
  <span class="code-keyword">public</span> Quote getQuote(
                        @WebParam(targetNamespace=<span class="code-quote">"http:<span class="code-comment">//demo.mycompany.com/types"</span>,
</span>                                  name=<span class="code-quote">"stockTicker"</span>,
                                  mode=Mode.IN)
                        <span class="code-object">String</span> ticker
  );
}
</pre>
</div></div>

<h3><a name="DevelopingaService-GeneratingWSDL"></a>Generating WSDL</h3>

<p>Once you have annotated your code, you can generate a WSDL contract for your service using the <b>java2wsdl</b> command.</p>

<h4><a name="DevelopingaService-Example"></a>Example</h4>

<p>The next example shows the WSDL contract generated for the SEI shown <a href="#DevelopingaService-Example8">above</a>:</p>

<p><a name="DevelopingaService-Example9"></a></p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Generated WSDL from an SEI</b></div><div class="codeContent panelContent">
<pre class="code-java">
&lt;?xml version=<span class="code-quote">"1.0"</span> encoding=<span class="code-quote">"UTF-8"</span>?&gt;
&lt;wsdl:definitions targetNamespace=<span class="code-quote">"http:<span class="code-comment">//demo.eric.org/"</span>
</span>                  xmlns:tns=<span class="code-quote">"http:<span class="code-comment">//demo.eric.org/"</span>
</span>		  xmlns:ns1=""
		  xmlns:xsd=<span class="code-quote">"http:<span class="code-comment">//www.w3.org/2001/XMLSchema"</span>
</span>		  xmlns:ns2=<span class="code-quote">"http:<span class="code-comment">//demo.eric.org/types"</span>
</span>		  xmlns:soap=<span class="code-quote">"http:<span class="code-comment">//schemas.xmlsoap.org/wsdl/soap/"</span>
</span>		  xmlns:wsdl=<span class="code-quote">"http:<span class="code-comment">//schemas.xmlsoap.org/wsdl/"</span>&gt;
</span>  &lt;wsdl:types&gt;
    &lt;xsd:schema&gt;
      &lt;xs:complexType name=<span class="code-quote">"quote"</span>&gt;
        &lt;xs:sequence&gt;
          &lt;xs:element name=<span class="code-quote">"ID"</span> type=<span class="code-quote">"xs:string"</span> minOccurs=<span class="code-quote">"0"</span>/&gt;
          &lt;xs:element name=<span class="code-quote">"time"</span> type=<span class="code-quote">"xs:string"</span> minOccurs=<span class="code-quote">"0"</span>/&gt;
          &lt;xs:element name=<span class="code-quote">"val"</span> type=<span class="code-quote">"xs:<span class="code-object">float</span>"</span>/&gt;
        &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
    &lt;/xsd:schema&gt;
  &lt;/wsdl:types&gt;
  &lt;wsdl:message name=<span class="code-quote">"getStockQuote"</span>&gt;
    &lt;wsdl:part name=<span class="code-quote">"stockTicker"</span> type=<span class="code-quote">"xsd:string"</span>&gt;
    &lt;/wsdl:part&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:message name=<span class="code-quote">"getStockQuoteResponse"</span>&gt;
    &lt;wsdl:part name=<span class="code-quote">"updatedQuote"</span> type=<span class="code-quote">"tns:quote"</span>&gt;
    &lt;/wsdl:part&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:portType name=<span class="code-quote">"quoteReporter"</span>&gt;
    &lt;wsdl:operation name=<span class="code-quote">"getStockQuote"</span>&gt;
      &lt;wsdl:input name=<span class="code-quote">"getQuote"</span> message=<span class="code-quote">"tns:getStockQuote"</span>&gt;
    &lt;/wsdl:input&gt;
      &lt;wsdl:output name=<span class="code-quote">"getQuoteResponse"</span> message=<span class="code-quote">"tns:getStockQuoteResponse"</span>&gt;
    &lt;/wsdl:output&gt;
    &lt;/wsdl:operation&gt;
  &lt;/wsdl:portType&gt;
  &lt;wsdl:binding name=<span class="code-quote">"quoteReporterBinding"</span> type=<span class="code-quote">"tns:quoteReporter"</span>&gt;
    &lt;soap:binding style=<span class="code-quote">"rpc"</span> transport=<span class="code-quote">"http:<span class="code-comment">//schemas.xmlsoap.org/soap/http"</span>/&gt;
</span>    &lt;wsdl:operation name=<span class="code-quote">"getStockQuote"</span>&gt;
      &lt;soap:operation style=<span class="code-quote">"rpc"</span>/&gt;
      &lt;wsdl:input name=<span class="code-quote">"getQuote"</span>&gt;
        &lt;soap:body use=<span class="code-quote">"literal"</span>/&gt;
      &lt;/wsdl:input&gt;
      &lt;wsdl:output name=<span class="code-quote">"getQuoteResponse"</span>&gt;
        &lt;soap:body use=<span class="code-quote">"literal"</span>/&gt;
      &lt;/wsdl:output&gt;
    &lt;/wsdl:operation&gt;
  &lt;/wsdl:binding&gt;
  &lt;wsdl:service name=<span class="code-quote">"quoteReporterService"</span>&gt;
    &lt;wsdl:port name=<span class="code-quote">"quoteReporterPort"</span> binding=<span class="code-quote">"tns:quoteReporterBinding"</span>&gt;
      &lt;soap:address location=<span class="code-quote">"http:<span class="code-comment">//localhost:9000/quoteReporterService"</span>/&gt;
</span>    &lt;/wsdl:port&gt;
  &lt;/wsdl:service&gt;
&lt;/wsdl:definitions&gt;
</pre>
</div></div>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action" class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/CXF20DOC/Developing+a+Service">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=27270&revisedVersion=21&originalVersion=20">View Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CXF20DOC/Developing+a+Service?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message