JAX-WS is bundled with JDK 1.6, which makes Java web service development easier to develop. This tutorial shows you how to do the following tasks:
- Create a SOAP-based RPC style web service endpoint by using JAX-WS.
- Create a Java web service client manually.
- Create a Java web service client via wsimport tool.
- Create a Ruby web service client.
You will be surprise of how simple it is to develop a RPC style web service in JAX-WS.
In general words, “web service endpoint” is a service which published outside for user to access; where “web service client” is the party who access the published service.
JAX-WS Web Service End Point
The following steps showing how to use JAX-WS to create a RPC style web service endpoint.
1. Create a Web Service Endpoint Interface
File : HelloWorld.java
package com.mkyong.ws;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
//Service Endpoint Interface
@WebService
@SOAPBinding(style = Style.RPC)
public interface HelloWorld{
@WebMethod String getHelloWorldAsString(String name);
}
2. Create a Web Service Endpoint Implementation
File : HelloWorldImpl.java
package com.mkyong.ws;
import javax.jws.WebService;
//Service Implementation
@WebService(endpointInterface = "com.mkyong.ws.HelloWorld")
public class HelloWorldImpl implements HelloWorld{
@Override
public String getHelloWorldAsString(String name) {
return "Hello World JAX-WS " + name;
}
}
3. Create a Endpoint Publisher
File : HelloWorldPublisher.java
package com.mkyong.endpoint;
import javax.xml.ws.Endpoint;
import com.mkyong.ws.HelloWorldImpl;
//Endpoint publisher
public class HelloWorldPublisher{
public static void main(String[] args) {
Endpoint.publish("http://localhost:9999/ws/hello", new HelloWorldImpl());
}
}
Run the endpoint publisher, and your “hello world web service” is deployed in URL “http://localhost:9999/ws/hello“.
4. Test It
You can test the deployed web service by accessing the generated WSDL (Web Service Definition Language) document via this URL “http://localhost:9999/ws/hello?wsdl” .
Web Service Clients
Ok, web service is deployed properly, now let’s see how to create web service client to access to the published service.
1. Java Web Service Client
Without tool, you can create a Java web service client like this :
package com.mkyong.client;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import com.mkyong.ws.HelloWorld;
public class HelloWorldClient{
public static void main(String[] args) throws Exception {
URL url = new URL("http://localhost:9999/ws/hello?wsdl");
//1st argument service URI, refer to wsdl document above
//2nd argument is service name, refer to wsdl document above
QName qname = new QName("http://ws.mkyong.com/", "HelloWorldImplService");
Service service = Service.create(url, qname);
HelloWorld hello = service.getPort(HelloWorld.class);
System.out.println(hello.getHelloWorldAsString("mkyong"));
}
}
Output
Hello World JAX-WS mkyong
2. Java Web Service Client via wsimport tool
Alternative, you can use “wsimport” tool to parse the published wsdl file, and generate necessary client files (stub) to access the published web service.
This wsimport tool is bundle with the JDK, you can find it at “JDK_PATH/bin” folder.
Issue “wsimport” command.
wsimport -keep http://localhost:9999/ws/hello?wsdl
It will generate necessary client files, which is depends on the provided wsdl file. In this case, it will generate one interface and one service implementation file.
File : HelloWorld.java
package com.mkyong.ws;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
/**
* This class was generated by the JAX-WS RI.
* JAX-WS RI 2.1.1 in JDK 6
* Generated source version: 2.1
*
*/
@WebService(name = "HelloWorld", targetNamespace = "http://ws.mkyong.com/")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public interface HelloWorld {
/**
*
* @param arg0
* @return
* returns java.lang.String
*/
@WebMethod
@WebResult(partName = "return")
public String getHelloWorldAsString(
@WebParam(name = "arg0", partName = "arg0")
String arg0);
}
File : HelloWorldImplService.java
package com.mkyong.ws;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;
import javax.xml.ws.WebServiceFeature;
/**
* This class was generated by the JAX-WS RI.
* JAX-WS RI 2.1.1 in JDK 6
* Generated source version: 2.1
*
*/
@WebServiceClient(name = "HelloWorldImplService",
targetNamespace = "http://ws.mkyong.com/",
wsdlLocation = "http://localhost:9999/ws/hello?wsdl")
public class HelloWorldImplService
extends Service
{
private final static URL HELLOWORLDIMPLSERVICE_WSDL_LOCATION;
static {
URL url = null;
try {
url = new URL("http://localhost:9999/ws/hello?wsdl");
} catch (MalformedURLException e) {
e.printStackTrace();
}
HELLOWORLDIMPLSERVICE_WSDL_LOCATION = url;
}
public HelloWorldImplService(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}
public HelloWorldImplService() {
super(HELLOWORLDIMPLSERVICE_WSDL_LOCATION,
new QName("http://ws.mkyong.com/", "HelloWorldImplService"));
}
/**
*
* @return
* returns HelloWorld
*/
@WebEndpoint(name = "HelloWorldImplPort")
public HelloWorld getHelloWorldImplPort() {
return (HelloWorld)super.getPort(
new QName("http://ws.mkyong.com/", "HelloWorldImplPort"),
HelloWorld.class);
}
/**
*
* @param features
* A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy.
* Supported features not in the <code>features</code> parameter will have their default values.
* @return
* returns HelloWorld
*/
@WebEndpoint(name = "HelloWorldImplPort")
public HelloWorld getHelloWorldImplPort(WebServiceFeature... features) {
return (HelloWorld)super.getPort(
new QName("http://ws.mkyong.com/", "HelloWorldImplPort"),
HelloWorld.class,
features);
}
}
Now, create a Java web service client which depends on the above generated files.
package com.mkyong.client;
import com.mkyong.ws.HelloWorld;
import com.mkyong.ws.HelloWorldImplService;
public class HelloWorldClient{
public static void main(String[] args) {
HelloWorldImplService helloService = new HelloWorldImplService();
HelloWorld hello = helloService.getHelloWorldImplPort();
System.out.println(hello.getHelloWorldAsString("mkyong"));
}
}
Here’s the output
Hello World JAX-WS mkyong
3. Ruby Web Service Client
Often time, web service development is mixed use with other programming language. So, here’s a Ruby web service client example, which is used to access the published JAX-WS service.
# package for SOAP-based services
require 'soap/wsdlDriver'
wsdl_url = 'http://localhost:9999/ws/hello?wsdl'
service = SOAP::WSDLDriverFactory.new(wsdl_url).create_rpc_driver
# Invoke service operations.
data1 = service.getHelloWorldAsString('mkyong')
# Output results.
puts "getHelloWorldAsString : #{data1}"
Output
getHelloWorldAsString : Hello World JAX-WS mkyong
Tracing SOAP Traffic
From top to bottom, showing how SOAP envelope flows between client and server. See #1 web service client again :
URL url = new URL("http://localhost:9999/ws/hello?wsdl");
QName qname = new QName("http://ws.mkyong.com/", "HelloWorldImplService");
Service service = Service.create(url, qname);
HelloWorld hello = service.getPort(HelloWorld.class);
System.out.println(hello.getHelloWorldAsString("mkyong"));
To monitor SOAP traffic is very easy, see this guide – “How to trace SOAP message in Eclipse IDE“.
1. Request a WSDL file
First, client send a wsdl request to service endpoint, see HTTP traffic below :
Client send request :
GET /ws/hello?wsdl HTTP/1.1
User-Agent: Java/1.6.0_13
Host: localhost:9999
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
Server send response :
HTTP/1.1 200 OK
Transfer-encoding: chunked
Content-type: text/xml;charset=utf-8
<?xml version="1.0" encoding="UTF-8"?>
<definitions
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://ws.mkyong.com/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="http://ws.mkyong.com/"
name="HelloWorldImplService">
<types></types>
<message name="getHelloWorldAsString">
<part name="arg0" type="xsd:string"></part>
</message>
<message name="getHelloWorldAsStringResponse">
<part name="return" type="xsd:string"></part>
</message>
<portType name="HelloWorld">
<operation name="getHelloWorldAsString" parameterOrder="arg0">
<input message="tns:getHelloWorldAsString"></input>
<output message="tns:getHelloWorldAsStringResponse"></output>
</operation>
</portType>
<binding name="HelloWorldImplPortBinding" type="tns:HelloWorld">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"></soap:binding>
<operation name="getHelloWorldAsString">
<soap:operation soapAction=""></soap:operation>
<input>
<soap:body use="literal" namespace="http://ws.mkyong.com/"></soap:body>
</input>
<output>
<soap:body use="literal" namespace="http://ws.mkyong.com/"></soap:body>
</output>
</operation>
</binding>
<service name="HelloWorldImplService">
<port name="HelloWorldImplPort" binding="tns:HelloWorldImplPortBinding">
<soap:address location="http://localhost:9999/ws/hello"></soap:address>
</port>
</service>
</definitions>
2. hello.getHelloWorldAsString()
A second call, client put method invoke request in SOAP envelope and send it to service endpoint. At the service endpoint, call the requested method and put the result in a SOAP envelope and send it back to client.
Client send request :
POST /ws/hello HTTP/1.1
SOAPAction: ""
Accept: text/xml, multipart/related, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Content-Type: text/xml; charset=utf-8
User-Agent: Java/1.6.0_13
Host: localhost:9999
Connection: keep-alive
Content-Length: 224
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getHelloWorldAsString xmlns:ns2="http://ws.mkyong.com/">
<arg0>mkyong</arg0>
</ns2:getHelloWorldAsString>
</S:Body>
</S:Envelope>
Server send response :
HTTP/1.1 200 OK
Transfer-encoding: chunked
Content-type: text/xml; charset=utf-8
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getHelloWorldAsStringResponse xmlns:ns2="http://ws.mkyong.com/">
<return>Hello World JAX-WS mkyong</return>
</ns2:getHelloWorldAsStringResponse>
</S:Body>
</S:Envelope>
Done, any comments are appreciated.
I have a service created using power builder,
I tested the service using wsimport tools,
and i get error as bellow
[Error] The package name ‘__’.__” used for this schema is not a valid package name
line 4 of http://localhost/webservice/n_webservice?wsdl
Why am I taking this exception ?
Thank you very much
HI ,
Please clarify my doubt . i didn’t find the web.xml in SOAP WS examples. Actually web.xml should be there in proper location right?
I am getting com.sun.xml.internal.ws.model.RuntimeModelerException: class: com.demo.jaxws.impl.CustomerService could not be found exception which is because no artifacts are found in the project after I googled it. Now when I am trying wsgen -keep -cp CustomerService.class it’s giving me MISSING SEI
Simply the the best!
Thanks dear you saved my life.
Dear Yong,
at point 1. Java WS Client I get the next error on ” Service service = Service.create(url, qname);”
***
main, WRITE: TLSv1 Handshake, length = 173
main, READ: TLSv1 Alert, length = 2
main, RECV TLSv1 ALERT: fatal, handshake_failure
main, called closeSocket()
main, handling exception: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
This is because of wsdl definition is at a https:// location and TLSv1.2 is forced but JVM use only TLSv1. Is there any solution to this?
Thanks in advance.
https://stackoverflow.com/questions/19533904/is-not-a-valid-service-exception-in-jax-ws/45907977#45907977
this is so bad ..its making issues in my eclipse ..not properly explained..when wsdl got generated and where
After reading carefully your articles on SOAP services I still did not get it –
what is the difference Document and RPC style web services.?
Except of course for the annotation attribute @SOAPBinding(style = Style.DOCUMENT/RPC) which judging by your code does not produce any differences. Or at least you did not mention it at all.
I read somewhere that RPC and Document wsdl are different in structure – and I noticed that
tag in wsdl has in it in case of Document style
Is that the only difference – that Document style wsdl is (can?) be validated?
Thanks
why my request is http 1.0 ? how can make the request to http 1.1
How to add attachments(any javax DataHandler) to SOAP request which is generated using wsimport from wsdl?
I am not able to find any method where in I can add attachment
Great article
I really like these tutorials – you manage to show the simplest possible examples that work. It has given me a nice start in the web services world.
Hi,
I tried to add more API to the WebService besides:
@WebMethod String getHelloWorldAsString(String name);
so now my interface is (The impl is implementing the getFoo method):
@WebMethod String getHelloWorldAsString(String name);
@WebMethod String getFoo(Integer i);
And then I republishing the wsdl – Endpoint.publish(“http://localhost:9999/ws/hello”, new HelloWorldImpl());
And getting the following exception:
ServerMgr.createContext(String) line: not available
HttpEndpoint.publish(String) line: not available
EndpointImpl.publish(String) line: not available
ProviderImpl.createAndPublishEndpoint(String, Object) line: not available
Endpoint.publish(String, Object) line: not available
HelloWorldPublisher.main(String[]) line: 10
What should be changed so there would be no exception? I tried PortDifferent names. non worked.
Thanks in advance.
I find that the information you provide is consistently accurate and helpful. Thank you for being the beacon of light.
how to compose jax-ws web service? Is it in the same way as other web services?
Poor explanation. Didn’t work at all.
Wow. exactly what I was looking for. Works like a sharm 🙂
@mkyong web links are not working , please update
I’d like to receive a xlm file from a list of my object on my browser . But I couldn’t understand how can I invoke a operation (method) just typing a url in my browser. my implementation of my interface:
@GET
@Produces(“text/xml”)
@WebMethod(operationName=”lista”)
public String listarVagas() {
String streamXML = “”;
List vagas = new ArrayList();
StringBuffer out = new StringBuffer();
vagas = myejb.buscarVagasAtivas();
XStream stream = new XStream(new StaxDriver());
streamXML = stream.toXML(vagas);
out.append(streamXML);
return out.toString();
}
when I type : “http://localhost:8080/estagios/Vagas?xsd=1” I expected to receive a xml file but I just get a blank page
hello… I’m trying to use this example in eclipse. but i’m not able to do it. pls help me..
Hi MKyong, I have WSDL file in my local machine and wanted to generate the request file either in string or in seperate file, So I can later use it for different tags in webservice. I searched for java code to get it done, please help me on this.
Thanks in advance
Hello Mkyong,
How can I write a python client in same way? Any idea or suggestions?
hi
How can i get client files (stub) without using “wsimport” tool. Means how can i get client files (stub) using simple java code?
Dear Yong,
thank you for your fantastic site.
Your efforts are so much appreciated.
Regarding this article.
Unfortunately it is beyond my understanding now:
1. where wsdl accessible at
http://localhost:9999/ws/hello?wsdl
is located.
It is not on the drive but how then the clients on any other machine manage to see it?
2. is it correct that I may indicate ANY URI when making use of endpoint publisher?
Endpoint.publish(“http://localhost:9999/ws/hello”, …
Can I write it like say
Endpoint.publish(“http://172.56.3.4:9999/ws/hello”, …) ?
If so should I upload smth to the server with that ip?
And suppose I have some server address from outside the locale network and inner network address?
Is it correct that outer ip gives access tot he service to any machine on the web
while providing local network address shares the service with any machine in the local network?
Thank you in advance
Hi MKYoung,
it is really good tutorial about JAX-WS for the first steps. Thank you very much.
Mr MKyong are you there ? Are you resolve my problem or not let me know? no body was there to resolve the below issue?
I have tried your Helloworld example with JAX-WS.
I am getting below exception while run the client program. could you please correct me any configurations are missing
Exception in thread “main” javax.xml.ws.WebServiceException: WSDL http://localhost:9080/HelloworldWS/hello/HelloWorld.wsdl contains no service definition.
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:153)
at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:267)
at com.sun.xml.internal.ws.client.WSServiceDelegate.(WSServiceDelegate.java:230)
at com.sun.xml.internal.ws.client.WSServiceDelegate.(WSServiceDelegate.java:178)
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:93)
at javax.xml.ws.Service.(Service.java:57)
at javax.xml.ws.Service.create(Service.java:687)
at com.mkyong.ws.client.HelloWorldClient.main(HelloWorldClient.java:19)
I am mentiontioning my code here:
Helloworld interface:
/**
*
*/
package com.mkyong.ws;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
//Service Endpoint Interface
@WebService
@SOAPBinding(style = Style.RPC)
public interface HelloWorld {
@WebMethod String getHelloWorldAsString(String name);
}
implementation:
package com.mkyong.ws;
import javax.jws.WebService;
//Service Implementation
@WebService(endpointInterface = “com.mkyong.ws.HelloWorld”)
public class HelloWorldImpl implements HelloWorld {
@Override
public String getHelloWorldAsString(String name) {
return “Hello World JAX-WS ” + name;
}
}
publisher:
package com.mkyong.endpoint;
import javax.xml.ws.Endpoint;
import com.mkyong.ws.HelloWorldImpl;
//Endpoint publisher
public class HelloWorldPublisher {
public static void main(String[] args) {
Endpoint.publish(“http://localhost:9080/HelloworldWS/hello”, new HelloWorldImpl());
}
}
client:
package com.mkyong.ws.client;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import com.mkyong.ws.HelloWorld;
public class HelloWorldClient {
public static void main(String[] args) throws Exception {
URL url = new URL(“http://localhost:9080/HelloworldWS/hello/HelloWorld.wsdl”);
//1st argument service URI, refer to wsdl document above
//2nd argument is service name, refer to wsdl document above
QName qname = new QName(“http://ws.mkyong.com/”, “HelloWorldImplService”);
Service service = Service.create(url, qname);
HelloWorld hello = service.getPort(HelloWorld.class);
System.out.println(hello.getHelloWorldAsString(“mkyong”));
}
}
web.xml:
HelloworldWS
default.jsp
HelloServiceImpl
com.mkyong.ws.HelloWorldImpl
1
HelloServiceImpl
/hello
webservices.xml:
HelloworldService
hello
ts:hello
ts:helloPort
com.mkyong.ws.HelloWorld
HelloServiceImpl
specify the url of wsdl as part of the proxy create process : Service.create(url, qName);
Hi Mkyong
I have tried your Helloworld example with JAX-WS.
I am getting below exception while run the client program. could you please correct me any configurations are missing
Exception in thread “main” javax.xml.ws.WebServiceException: WSDL http://localhost:9080/HelloworldWS/hello/HelloWorld.wsdl contains no service definition.
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:153)
at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:267)
at com.sun.xml.internal.ws.client.WSServiceDelegate.(WSServiceDelegate.java:230)
at com.sun.xml.internal.ws.client.WSServiceDelegate.(WSServiceDelegate.java:178)
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:93)
at javax.xml.ws.Service.(Service.java:57)
at javax.xml.ws.Service.create(Service.java:687)
at com.mkyong.ws.client.HelloWorldClient.main(HelloWorldClient.java:19)
I am mentiontioning my code here:
Helloworld interface:
/**
*
*/
package com.mkyong.ws;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
//Service Endpoint Interface
@WebService
@SOAPBinding(style = Style.RPC)
public interface HelloWorld {
@WebMethod String getHelloWorldAsString(String name);
}
implementation:
package com.mkyong.ws;
import javax.jws.WebService;
//Service Implementation
@WebService(endpointInterface = “com.mkyong.ws.HelloWorld”)
public class HelloWorldImpl implements HelloWorld {
@Override
public String getHelloWorldAsString(String name) {
return “Hello World JAX-WS ” + name;
}
}
publisher:
package com.mkyong.endpoint;
import javax.xml.ws.Endpoint;
import com.mkyong.ws.HelloWorldImpl;
//Endpoint publisher
public class HelloWorldPublisher {
public static void main(String[] args) {
Endpoint.publish(“http://localhost:9080/HelloworldWS/hello”, new HelloWorldImpl());
}
}
client:
package com.mkyong.ws.client;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import com.mkyong.ws.HelloWorld;
public class HelloWorldClient {
public static void main(String[] args) throws Exception {
URL url = new URL(“http://localhost:9080/HelloworldWS/hello/HelloWorld.wsdl”);
//1st argument service URI, refer to wsdl document above
//2nd argument is service name, refer to wsdl document above
QName qname = new QName(“http://ws.mkyong.com/”, “HelloWorldImplService”);
Service service = Service.create(url, qname);
HelloWorld hello = service.getPort(HelloWorld.class);
System.out.println(hello.getHelloWorldAsString(“mkyong”));
}
}
web.xml:
HelloworldWS
default.jsp
HelloServiceImpl
com.mkyong.ws.HelloWorldImpl
1
HelloServiceImpl
/hello
webservices.xml:
HelloworldService
hello
ts:hello
ts:helloPort
com.mkyong.ws.HelloWorld
HelloServiceImpl
what are changes i need to do to client program to make soap header element appear in client send request.please help me
I am getting error: cannot get a wsdl maximum number of redirects(5) reached.
I am getting error: cannot get a wsdl maximum number of redirects(5) reached
I did not understand anything, I feel bad
I am able to see the WSDL request/response in the TCP/IP monitor..But, i am not able to see the second request/response.. can anyone pl help me ?
This is the coolest thing I’ve read all summer long in my internship. Thanks mkyong!
I am spending some time getting up to speed with some technologies including Java and Heroku. I found your tutorial on JAX-WS very helpful.
I made some small changes in order to run on Jetty. My web service, based on your example ran quickly on my development machine. However, when I tried to push the code onto the Heroku platform it did not connect to their http service and crashed each time after waiting 60 seconds. I spend many hours researching the problem and trying things. I finally got it working by publishing the Endpoint to ip address 0.0.0.0 instead of “localhost” (and obviously the port number specified by Heroku’s PORT environment variable.
I just spend a couple of hours as well, until I found this comment.
Hi Yong,
I have a doubt on the provider. Dont we require a server to deploy that code. If so where is it getting deployed??
It is not getting deployed anywhere. Your JVM is creating a JAX-WS runtime environment, publish the service and open the socket (on the ip address and port) for clients to access.
Hey, the tutorial is really good. Easy to understand. I have a doubt. How come the wsdl url is protected with a certificate and you need to configure the certificate before accessing the web services. How can we accomplish it in java with tomcat 7 ? Can you provide an example for that ?
Hi MKYoung,
Please describe why RPC and document/literal style both generates same kind of request response structure.
We use the binding styles to change the WSDL to SOAP message conversion style.
Both of your examples (RPC and doc/lit) generates same output.
Hello Mkyong,
I have a question, and needs a bit of explanation.
When we create Java Web Service Client via wsimport tool, it creates two files, HelloWorld.java, and HelloWorldImplService.
My question is that, we all ready have HelloWorld.java interface that we have created when creating the web service, and now there is another HelloWorld.java interface, how does the two files get distinguished?
regards Harbir
there is no need to generate the service-endpoint-stubs when you are the creator of the web service; wsimport tool is for third party developers who want to consume your web service for developing customer facing apps. since they do not have your actual web-service-endpoint-interfaces they need to generate those from the ‘exported’ wsdl using wsimport
you have to add HElloWorland HelloWorldImplService in the package of the client Side.
so they will not be a conflict between the two files HelloWorld as they are not in the same directory.
Great tuto. Thanks a lot man and keep it up please 🙂
Hello,
I’m new in the web service but I can’t have the wsdl file when I go on “http://localhost:9999/ws/hello?wsdl”.
I tried to keep going but in HelloWorldClient, I don’t know what to write in Qname : QName qname = new QName(“http:// ?????”, “HelloWorldImplService”).
So, I’m stuck :'(.
Finally, I think that my code can’t generate the wsdl file. I don’t see it in any browser, I have “Page not Found”… I tried a lot of tuto on SOAP with axis2 or cfx but none works :(.
same with me 🙁
Thank you for taking the time of writing this up!
I was looking at your example of “wsimport” and I think that the implementation class is missing the override of the “getHelloWorldAsString” method from the interface. This is done correctly when you created the classes without the automated tool. Is it somewhere else in the automated implementation or was this a mistake? Please let me know if I am reading this incorrectly. Thank you for your time.
You write easy to understand stuff.
My question is – can one create first type of client when one does not have .class file that is referenced in the call “service.getPort(HelloWorld.class)”.
I am trying to hit one of the yahoo mail wdsl, but since I dont have the .class file the code is not compiling. Does it mean the only way I can write my client is via use of wsimport?
I guess the first type of client is just a “shortcut” demo. In real world you can’t have HelloWorld.class file. You can only get it via parsing the wsdl file, using wsimport or your own code.
but that short cut made things a lot clear as to how it works at the publisher side, and how it works on the subscriber side. in fact, when we have a chance to ship our SDK libraries to our b2b customers, then it is better to include our web service endpoint interfaces too so that they don’t need to generate the stubs if they are to consume our web service in Java clients.
hey…for me getPort takes long time from 3 to 10 seconds to get me the port details…what could be the issue?…thanks
Hi,
I have a similar webservice call in my project and when try to run my code fails in the initialization part mentioned below, and it doesnt throw any error and my code goes to the bottom of the stack.
//similar place as below my project code fails.
public HelloWorldImplService() {
super(HELLOWORLDIMPLSERVICE_WSDL_LOCATION,
new QName(“http://ws.mkyong.com/”, “HelloWorldImplService”));
}
Can you please tell me how I should know what error is being thrown or how could I rectify the error.
P.S : I see the webservice is being responsive.
how to customize this to our own field name??
Hi,
First of all, I like your tutorials and you did a fabulous job by creating this website.
Anyway, I just started web services and I tried creating the RPC style web services and built the web service client manually. I used Tomcat 6 to deploy the application
After I run the publisher, I am not able to see the WSDL at the given location
http://localhost:9999/ws/hello?wsdl
I am getting the “HTTP Status 404 – /ws/hello” error.
description The requested resource (/ws/hello) is not available.
But I ignored this error and I ran the web service client and I am getting the expected output. But I do not understand why I am unable to access the WSDL. Can you help?
Hi all,
In HelloWorldClient.java, is there one line of code is:
QName qname = new QName(“http://ws.mkyong.com/”, “HelloWorldImplService”);
How can i change this url ‘http://ws.mkyong.com/’ to my local adress, i try to change this to
QName qname = new QName(“http://localhost:9999/ws/hello”, “HelloWorldImplService”);
And it threw an exception:
Exception in thread “main” javax.xml.ws.WebServiceException: {http://localhost:9999/ws/hello}HelloWorldImplService is not a valid service. Valid services are: {http://ws.mkyong.com/}HelloWorldImplService
at com.sun.xml.internal.ws.client.WSServiceDelegate.(WSServiceDelegate.java:223)
at com.sun.xml.internal.ws.client.WSServiceDelegate.(WSServiceDelegate.java:168)
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:96)
at javax.xml.ws.Service.(Service.java:77)
at javax.xml.ws.Service.create(Service.java:707)
at com.mkyong.client.HelloWorldClient.main(HelloWorldClient.java:18)
Please tell me why, thanks you.
You are supposed to give the URI name and package/class name of your local machine. Just issue the WSDL URL which you created in Publisher class in a browser. You would see the status of the web service under which you have Endpoint -> Service Name. You have to use this for namespaceURI(http://) and localPart(Service) of QName constructor.
Hello,
Thanks for the article. I tried the example but when calling the method, it’s running forever and is not returning anything, what could the problem be? I generated the artifact classes using eclipse and not the tool mentioned here.
Thanks.
In fact it’s returning, but after way too long, like more than 5 minutes… what could be the reason?
it worked by setting the http version to 1.1 in the ImplPort class…:
_call.setProperty(MessageContext.HTTP_TRANSPORT_VERSION, HTTPConstants.HEADER_PROTOCOL_V11);
Thanks. I’ve been looking for a long time to find a simple, no nonsense Hello World example of WS server in Java, that has no clutter or assumption about whether you are using Eclipse or Netbeans or requires you to create a Web app, or wants to walk you through connecting databases etc. Just a few classes. Run them. Done. 10 mins total. Fantastic. Now I can build on that as I please.
Thank You.. your tutorial are simple and clear..
excellent article in Wsdl..thanks for helping us out in getting ready to use these concept in our projects…keep it up…
Hi ..Nice tutorial.
Need clarification on the following:
Created the following 3 files as mentioned above..
1. Create a Web Service Endpoint Interface
2. Create a Web Service Endpoint Implementation
3. Create a Endpoint Publisher
while running the endpoint publisher.java file, I am getting the following error:
Exception in thread “main” com.sun.xml.internal.ws.model.RuntimeModelerException: class: HelloWorld could not be found
at com.sun.xml.internal.ws.model.RuntimeModeler.getPortTypeName(Unknown Source)
at com.sun.xml.internal.ws.server.EndpointFactory.createEndpoint(Unknown Source)
at com.sun.xml.internal.ws.api.server.WSEndpoint.create(Unknown Source)
at com.sun.xml.internal.ws.api.server.WSEndpoint.create(Unknown Source)
at com.sun.xml.internal.ws.transport.http.server.EndpointImpl.createEndpoint(Unknown Source)
at com.sun.xml.internal.ws.transport.http.server.EndpointImpl.publish(Unknown Source)
at com.sun.xml.internal.ws.spi.ProviderImpl.createAndPublishEndpoint(Unknown Source)
at javax.xml.ws.Endpoint.publish(Unknown Source)
at com.sripada.HelloWorldPublisher.main(HelloWorldPublisher.java:8)
—-Please help me in resolvig this issue ..
look into java package management. Put your source code in the correct dirs (~/com/mkyong/ws, ~/com/mkyong/client, ~/com/mkyong/enabler) and compile from the top-most dir (cd ~ ; javac com/mkyong/client/*java), call/envoke the main() method thus: java com.mkyong.client.HelloWorldClient
Better? 🙂
Please give full package path in the implementation class.
…..
@WebService(endpointInterface=”com.arun.ws.HelloWorld”)
public class HelloWorldImpl implements HelloWorld {
…..
it solved the issue for me.
I am new to webservice and i tried this tutorial but am facing the below stack trace pls help me ….
Exception in thread “main” Server Runtime Error: class: HelloWorldImpl could not be found
at com.sun.xml.internal.ws.transport.http.server.HttpEndpoint.publish(HttpEndpoint.java:269)
at com.sun.xml.internal.ws.transport.http.server.EndpointImpl.publish(EndpointImpl.java:87)
at com.sun.xml.internal.ws.spi.ProviderImpl.createAndPublishEndpoint(ProviderImpl.java:59)
at javax.xml.ws.Endpoint.publish(Endpoint.java:156)
at com.suji.endpoint.HelloWorldPublisher.main(HelloWorldPublisher.java:12)
Caused by: class: HelloWorldImpl could not be found
at com.sun.xml.internal.ws.modeler.RuntimeModeler.getPortTypeName(RuntimeModeler.java:1289)
at com.sun.xml.internal.ws.server.RuntimeEndpointInfo.doPortTypeNameProcessing(RuntimeEndpointInfo.java:274)
at com.sun.xml.internal.ws.transport.http.server.HttpEndpoint.fillEndpointInfo(HttpEndpoint.java:236)
at com.sun.xml.internal.ws.transport.http.server.HttpEndpoint.publish(HttpEndpoint.java:297)
at com.sun.xml.internal.ws.transport.http.server.HttpEndpoint.publish(HttpEndpoint.java:263)
… 4 more
Please give full package path in the implementation class.
…..
@WebService(endpointInterface=”com.arun.ws.HelloWorld”)
public class HelloWorldImpl implements HelloWorld {
…..
Thanks for this tuterial
very nice,
Please let me know , Suppose i have developed web service publisher in one java application, then i have developed the client in another java application, i want to access first java application method into the second java application .how can i do this??
Is it possible??
Is there need to import any package or add jar file, how it can make , Please explain , it’s important
Thanks
Vishwajeet
After hitting the service by the client I found the following error:
Exception in thread “main” javax.xml.ws.soap.SOAPFaultException: Found element Request but could not find matching RPC/Literal part
at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(Unknown Source)
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(Unknown Source)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(Unknown Source)
at com.sun.proxy.$Proxy35.getAccount(Unknown Source)
Any help on this??
Buenas tardes señor Mkyong,
quiero agradecerle, llevo todo el día buscando como se hace eso y en esta entrada encuentro la solución.
Leído desde Bogotá-Colombia!
Muchas gracias!
we implemented one jax-ws webservice using RPC style and published using the following url
http://localhost:9999/ws/hello?wsdl
but when we issue the
wsimport -keep http://localhost:9999/ws/hello?wsdl
command to generate the stub from the jdk bin command prompt wsimport throwing Can not get a WSDL maximum number of redirects(5) reached,
Very nice article to understand web service basics.
If I need to transfer XML, should I use the XML content in form of String? and then parse the string to get results? Any help would be appreciated.
Thanks, easy to understand
How to get hold of the interface of a web service? In my case I don’t have an interface with me, so I used the wsimport tool to do it for me, but the interface created like that is using a objectfactory which is using a wrapper object (name of the class same as that of the method). Hence I have to use all the classes created by the wsimport tool. Should I have to write the interface myself ?
Valuable tutorial
Thanks for great article. It very easy to understand web services basic with it.
But in attached sources archive is one little error. In HelloWorldPublisher.java endpoint port is 9999
Endpoint.publish("http://localhost:9999/ws/hello", new HelloWorldImpl());when in HelloWorldClient.java port is 8888
URL url = new URL("http://localhost:8888/ws/hello?wsdl");After correction to same port app work good.
Best regards
You are right,Alex!
thanks for posting this tutorial..
It was really helpful…
Hello Sir,
Thanks for sharing such helpful and easy to understand tutorials.
I need to consume a web service provided by a client. If i follow the 1st option mentioned in this article. Do i need to create client using
?
I have WSDL.
Please guide. Thanks again !!!
Hi,
You can use :
wsimport “D:\WSDLfile.wsdl” -s “c:\JavaProyect\src”
wsimport “http://www.domain.com/ServiceName?wsdl” -s “c:\JavaProyect\src”
Best Regards
Thanks for the reply.
So, Does it mean that i have to create client for this?
Now you need to create the Web service client from the interfaces generated by the wsimport too
Yes that is what i meant.
Here in this article there are two ways suggested to develop web service client.
In second one it is mentioned that you need to create web service client using wsimport while in first it isn’t.
So, i was under impression that if we follow first approach then we won’t require to create web service client.
Please correct me if i misunderstood. Thanks
Here, i am referring to 1. Java Web Service Client
In which it says “Without tool, you can create a Java web service client like this :”
Great article, thank you very much!
I have a question though: how do we do when we want to call a web service which we don’t have the source code? For example, I want to use the one which gives me the weather’s state. So how do I do in the client?
To generate the client need the URL or endpoint wsdl. You do not need to know the implementation
The first statement is : “JAX-WS is bundled with JDK 1.6”.
So, if I need web services on Websphere, will I need any infrastructure from the application server?
On Tomcat, will I use the web-service provided by JDK?
When will I need some external runtime like AXIS?
AXIS is a reference implementation of JAX-WS and provides additional features related to WS-Security, WS-RM, WS-Policy, etc. JDK also contains the reference implementation of JAX-WS but it provides only the basic JAX-WS implementation. If your project requires complex features then you should go for AXIS otherwise, go for JDK default implementation.
Such a great article. Could you also post an article for JAX-WS using maven.
Hi mykyong,
superb tutorial for beginners…and easy to understand..
Thank you so much for great article, it is very understandable for beginners.
But how to catch exceptions and pass it in SOAPFault tag?
For example, i have web service, which makes division operation. How to catch number division by zero and pass it in SOAPFault tag?
Its being some time I was searching intuitive tutorial where I could apply my theoretical knowledge to implement it in reality and finally with your help I am can confidently say I know WebServices.
Thanks a lot!!
Thanks for this example
I am purposefully not using any tool / IDE ( Eclipse ) and am copy pasting your code example in notepad
Then I am compiling the code on dos prompt
The one change is – I removed all the package statements in all classes in above example
When I try and run HelloWorldPublisher I get the exception
In HelloWorldImpl – I changed & commented the code as below:
//@WebService(endpointInterface = "com.mkyong.ws.HelloWorld") @WebService(endpointInterface = "HelloWorld") public class HelloWorldImpl implements HelloWorld{So while I should not have played with it – I dont seem to understand why it would matter ?
Thanks,
satish
Any Interface or a class should have a name space (which is nothing but the package name), so to implement any web service, we need to make sure we have given the correct namespace so the JAX-WS can publish/expose it’s methods correctly.
Excellent webservices……………..
thanks ..
I’m trying to get my publisher class to run in NetBeans 7.1, but it’s taking forever to run. Any ideas as to why this is happening?
I downloaded your code and checked it with the tcp/ip monitor from eclipse.
Unfortunately, I can only see the wsdl in the first and only response but not the soap traffic. That is because the url will be reread from within the wsdl and that is not with port 8888 but 9999.
Is there a little trick to tell the client not to use the URL from WSDL.
Hi, great article and great webpage overall, you have helped me many times.
I have a question, I need to call a WS method but I want to use a proxy.
How to do it? I tried
System.setProperty("http.proxyHost", "xxx.xxx.xxxx.xxx");but I dont want to do it as I might call the method from concurrent threads…
Thank you
Can you try with this :
BasicHttpBinding binding = new BasicHttpBinding(“APISoap”); /* APISoap is the name of the binding element in the app.config */
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.Basic;
binding.UseDefaultWebProxy = false;
binding.ProxyAddress = new Uri(string.Format(“http://{0}:{1}”, proxyIpAddress, proxyPort));
EndpointAddress endpoint = new EndpointAddress(“http://www.examplewebservice/api.asmx”);
WebServiceClient client = new WebServiceClient(binding, endpoint);
client.ClientCredentials.UserName.UserName = proxyUserName;
client.ClientCredentials.UserName.Password = proxyPassword;
thank you for the reply but I have already implemented a proxy by extending class ProxySelector.
Tried to implement this into my project but I’m unable to create JAXBContext due to handle interfaces?
Any ideas or suggestions?
Heres the message:
PingRequest is an interface, and JAXB can’t handle interfaces.
Just wanted to leave a note to say a great article/tutorial. Was trapsing through the Oracle site and my mind boggled thinking how complex this whole thing was, and then luckily I found this!
Thank you so much….. Very much useful for the beginners….
-How I can change Content-type to application / soap + xml, using a jaxws web service client,
-Anyone know how to configure the endpoint using HttpURLConnection, it should be noted that I can only assign the url to the wsdl definition but additionally need to assign different endpoint from this library. in conclusion would need to configure a url and a different endpoint to consume the service url
Thanks for the comprehensive tutorial. Do you know how to override the default behaviour of the ‘GET’ http Method when using ‘Endpoint’ ?
Your Articles are very easy to understand, thank you for the posting.
I have some problem in consuming the webservice with ssl.
I have generated the client code using Axis2
I have a certificate MyCertificate.cer generated as per the instructions from the Webservice Provider.
I am struct at coding the client could you please help or post an article how to consume ssl webservice , using certificate in cleint.
Nice article, thanks a lot.
I’m having a problem with the TCP/IP monitor view in Eclipse (Juno – on Mac OS X).
When I run your example (or my own code) I’m only seeing the first request/response i.e. I see all the expected request/response info you listed in the “1. Request a WSDL file” section
But nothing gets logged in TCP/IP monitor for this part “2. hello.getHelloWorldAsString()”. Even if I make multiple calls to it..
Has anyone else had this problem?
when i run my java project using netbeans7.1 and glassfish server 3.1.1
it shows Login form of my project as usual but when i click on register
button of login form,the next forms are not appearing and it shows
follow error message—– ‘Java Runtime Exception: 0x4F4F:524A
0x4120:5445 0x4348:0D0A’ what to do please help me to sort out this
problem
Also when i click on login button i get following error:
INFO: Java Runtime Exception: 0x4F4F:524A 0x4120:5445 0x4348:0D0A
Completed shutdown of Log manager service
Completed shutdown of GlassFish runtime
Please, help me to sort out this problem.
Hey, this is a good tutorial for beginners like me, I have a quick query , since my service is up and running how can I send query using address bar in my browser something similar to ?wsdl?id =1
Thank you for posting such content.
God Bless You man.
In firefox, when I go to:
http://localhost:9999/ws/hello?wsdl
I see a blank page. For some reason firefox is unable to display the wsdl. If you do “View Page Source” you will see the wsdl.
Sir ,your site content is very nice,can u specify any good book for java webservices
Hi MK, Thanks for ur valuable Examples.
In my project, a number services are there. And I want publish all of them.
But while publishing, It gives an error as “Address already in use”.
Pls help.
thanks in advance
Sisir
Thank you for the example , It is very nice and easy.
I have two concerns.
01. If I wanted to deploy the Producer in tomcat how can I do that, Please help to share the example.
02. How to change the targetName space
targetNamespace=”http://ws.mkyong.com/” which is appearing in the wsdl
I get this exception upon running the below command :
C:\Documents and Settings\Administrator>wsimport -keep http://localhost:9999/ws/
hello?wsdl
parsing WSDL…
Exception in thread “main” java.lang.IllegalArgumentException: http://www.w3.org
/2001/XMLSchema
at javax.xml.validation.SchemaFactory.newInstance(SchemaFactory.java:181
)
at com.sun.tools.internal.xjc.api.impl.s2j.SchemaCompilerImpl.bind(Schem
aCompilerImpl.java:214)
at com.sun.tools.internal.xjc.api.impl.s2j.SchemaCompilerImpl.bind(Schem
aCompilerImpl.java:74)
at com.sun.tools.internal.ws.processor.modeler.wsdl.JAXBModelBuilder.bin
d(JAXBModelBuilder.java:123)
at com.sun.tools.internal.ws.processor.modeler.wsdl.WSDLModeler.buildJAX
BModel(WSDLModeler.java:2234)
at com.sun.tools.internal.ws.processor.modeler.wsdl.WSDLModeler.internal
BuildModel(WSDLModeler.java:176)
at com.sun.tools.internal.ws.processor.modeler.wsdl.WSDLModeler.buildMod
el(WSDLModeler.java:122)
at com.sun.tools.internal.ws.wscompile.WsimportTool.run(WsimportTool.jav
a:172)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.tools.internal.ws.Invoker.invoke(Invoker.java:105)
at com.sun.tools.internal.ws.WsImport.main(WsImport.java:41)
Not able to parse abstract wsdl file. i have copied a wsdl in my local file system. by using that file i have to read the WSDL. Can you please help me to achieve this.
Hi, i cant try the WS with soapui.
Error loading [http://localhost:8888/ws/hello?WSDL]: org.apache.xmlbeans.XmlException: org.apache.xmlbeans.XmlException: error: Unexpected element: TAG_EN
What can i do?
Great tutorial, but for beginners it’s missing environment configuration steps just to run it properly.
You should mention also that first of all we should configure apache CXF or other service framework in our IDE ie. Eclipse.
For those who’re facing deployment issues, do the following:
(in Eclipse) go to Window->Preferences->Web Service->CXF 2.x Preferences
then set the CXF Runtime (download apache-cxf-2.x.x.zip first), navigate to folder that you’ve extracted zip file
In JAX-WS tab mark all annotations
and then restart IDE (for unbinding old webservice)
and remember while creating new dynamic web project to set-up the following:
Target runtime : none
Dynamic web module version : 2.5
Configuration : CXF Web Service Project v2.5
after that we can follow this tutorial, and we can enjoy hello world on the screen 🙂
Thanks for your input, but, you DO NOT need to any of CFX jar.
JAX-WS is inside the JDK. Get the downloaded project, import into Eclipse and run it.
Hi All,
I am working on the JAX WS webservice. Suppose i want to Generate Web service client from WSDL file without using the wsimport command. How can i do that? please reply.
Thanks
Abhijit
Its good for experienced Java Techie . I appreciate your work. for beginner need some groung knowledge for SOAP, WSDL, WEB SERVICE, JAXB, JAX WS . So please provide link for references also so that beginner can able to use ur site.
Great Thanks,
It was very simple and usefull for me.
I am getting below Exception:
Exception in thread “main” java.lang.NoSuchMethodError: com.sun.xml.ws.api.model.SEIModel.getJAXBContext()Lcom/sun/xml/bind/api/JAXBRIContext;
at com.sun.xml.wss.provider.wsit.SecurityTubeFactory.createTube(SecurityTubeFactory.java:198)
at com.sun.xml.ws.assembler.TubeCreator.createTube(TubeCreator.java:79)
at com.sun.xml.ws.assembler.TubelineAssemblerFactoryImpl$MetroTubelineAssembler.createClient(TubelineAssemblerFactoryImpl.java:121)
at com.sun.xml.ws.client.Stub.createPipeline(Stub.java:314)
at com.sun.xml.ws.client.Stub.(Stub.java:286)
at com.sun.xml.ws.client.Stub.(Stub.java:230)
at com.sun.xml.ws.client.Stub.(Stub.java:245)
at com.sun.xml.ws.client.sei.SEIStub.(SEIStub.java:91)
at com.sun.xml.ws.client.WSServiceDelegate.getStubHandler(WSServiceDelegate.java:725)
at com.sun.xml.ws.client.WSServiceDelegate.createEndpointIFBaseProxy(WSServiceDelegate.java:703)
at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:387)
at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:363)
at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:408)
at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:412)
at javax.xml.ws.Service.getPort(Service.java:161)
at sample.client.IrctcClerk1.main(IrctcClerk1.java:23)
When i try to start the 1. Java Web Service Client
Thanks mkyong…
Examples very easier to understand for beginners like me…
Hi,
I was trying the first point, but I get the next error in the main() method:
Exception in thread “main” javax.xml.ws.WebServiceException: Wrong binding ID: http://localhost:9999/ws/hello
at com.sun.xml.internal.ws.api.BindingID.parse(BindingID.java:263)
at com.sun.xml.internal.ws.spi.ProviderImpl.createEndpoint(ProviderImpl.java:86)
at javax.xml.ws.Endpoint.create(Endpoint.java:121)
at test.ws.TestWs.main(TestWs.java:9)
I’m using Eclipse to do the test and openJDK version 6.b24_1.11.3.
Any idea about what’s going on here?
Regards.
Hi Mkyong, can you please assist. I tried passing object parameters to the service but i keep getting the :
javax.xml.ws.WebServiceException: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '>' (code 62) expected '=' at [row,col {unknown-source}]: [1,193] at com.sun.xml.ws.server.sei.TieHandler.readRequest(TieHandler.java:253) at com.sun.xml.ws.db.DatabindingImpl.deserializeRequest(DatabindingImpl.java:166) at com.sun.xml.ws.db.DatabindingImpl.deserializeRequest(DatabindingImpl.java:260) at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:88) at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:961) at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:910)Reading around I discovered that my objects need to be “serialized by JAXB” or something like that but i a unable to find a clear tutorial the can help me archive that. Nice tutorial by the way, hope you can help
Hi Mkyong, can you please assist. I tried passing object parameters to the service but i keep getting the :
javax.xml.ws.WebServiceException: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '>' (code 62) expected '=' at [row,col {unknown-source}]: [1,193] at com.sun.xml.ws.server.sei.TieHandler.readRequest(TieHandler.java:253) at com.sun.xml.ws.db.DatabindingImpl.deserializeRequest(DatabindingImpl.java:166) at com.sun.xml.ws.db.DatabindingImpl.deserializeRequest(DatabindingImpl.java:260) at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:88) at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:961) at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:910)Reading around I discovered that my objects need to be “serialized by JAXB” or something like that but i a unable to find a clear tutorial the can help me archive that. Nice tutorial by the way, hope you can help.
Hi everbody.
Anyone know what I can use @WebServiceClient with HTTPS?
I configured the properties on Glassfish and the keystore, but I received this exception: “PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target.” when I connect the server using a method from this client.
Thanks!
There is a small mistake in your downloaded files:
in the HelloWorldClient.java file the
URL url = new URL(“http://localhost:8888/ws/hello?wsdl”);
should be:
URL url = new URL(“http://localhost:9999/ws/hello?wsdl”);
it’s 9999 in the web page, but 8888 in the downloaded files. Any way, very good tutoral
thanks a lot.
Thank you for this blog. This helped me to understand soap webservices. Many posts in the internet are explaining it, but not that simple, sometimes it’s so confusing. I found all I need here.
I understand, i suffered the same also, that why wrote this simple guide 🙂
Thanks a lot!
This example is very simple and it can help everyone to write a java ws server or client in a fast way!
Good work!
My small application and the publisher works fine, thanks for the tutorial! What should I do to run the app in jboss instead of using the endpoint publisher?
Very good site. You really elaborate on the smallest details which can sometimes be very confusing and not documented well. Thank you for clearing things up in a very straight forward way.
Just thank you again )
very useful tutorial helped me to understand Web services clearly. Appreciate your efforts
Hi dude, you have made my life easier. thanks a lot
you simply rock 🙂
All of your tutorial are really good. you are simply the best.
Thanks for the efforts. Webservices seem easy after reading your examples! I had ignored this topic out of boredom. You made it lively!
Good to know it did help you in somewhere 🙂
nice tutorials. Everything worked fine in the first try itself..
THanks a loot.
But tcp monitor did not show the traffic… did everything as instructed,
Double confirm your port setting, make sure it’s configure properly.
show a demo where in method accepts object as a parameter and return object
Simple and Excellent tutorial, well organized, keep up the good work.
I like a lot the clear style of the examples but unfortunately I cannot make them work. Everything compiles and runs fine but it doesnt generate an wsdl file at all
Keep on getting message that resource is not found which seems logical since there is no wsdl file
I’m using Netbeans and glassfish. I create a web project but don’t see webservices in the project tree .
Would it be possible to give me some guidance ?
As You’ve already grasped I’m a newbee to this.
Tx in advance
Don’t depends on Netbean to create web services, the generated web services from Netbean are complex and hard to maintenance (at least to me). JAX-WS is easily to develop, try create it without the help of Netbean, and you will learn a lot.
In WS development, normally we use code to wsdl method, because it ‘s fast and easy. Often time, we just code and never worry about the wsdl file. After WS is deployed, the WS runtime will generate wsdl file for WS client to consume, automatically.
My advice is don’t use netbean, it add too much extra codes on your WS, JAX-WS is a standard, a simple “java” command will get it run and deployed correctly.
thanks for such a great effort on jax-ws
Valid services are: {http://Model/}
Why am I taking this exception ?
please post your error stacks
how can i deploy this to prod server…
Hi,
in the source code, the class HelloWorldClient.java is not correct. While it shows in this page the next line:
URL url = new URL(“http://localhost:9999/ws/hello?wsdl”);
In the source code zip, it shows like that:
URL url = new URL(“http://localhost:8888/ws/hello?wsdl”);
So unless you change the port back to 9999 it will not work.
Ok, I did not realize that it was like that because it was calling the monitor first…
It’s really good point. I encountered the same problem. So once again if one runs HelloWorldClient.java without TCP Monitor one should put
URL url = new URL(“http://localhost:9999/ws/hello?wsdl”); to make everything work.
If one runs TCP Monitor and fill in TCP monitor information exactly as here https://mkyong.com/webservices/jax-ws/how-to-trace-soap-message-in-eclipse-ide/ then one really needs the following:
URL url = new URL(“http://localhost:8888/ws/hello?wsdl”);
Could the author take this remark to consideration?
In general this is good article.
it works nice
I am new to web service. Got a dumb question for you all.
The client already have created stuf code out of the WSDL. Why is it asking for WSDL again in the first request? Why can it just send the second request alone?
Also, I notice sometimes the endpoint does not include “?wsdl”. what is the difference between including “?wsdl” and not including “?wsdl”?
Any comment is appreciated. Thanks,
1. It’s depends on how you write the code. If you sure your client WSDL will never change, then just get a copy and integrate with your application locally.
2. WSDL is for SOAP service. Appending “?wsdl” at the end of the web service means to get the wsdl file content. Without “?wsdl” is the WS URL. For restful web service, it does not contains any of “?wsdl” as well.
Hope help.
That helps. Thanks a lot. And I love your site. Easy to follow and very well organized. Better than any other tutorial site I have ever seen. Keep up the good work 🙂
Thanks a lot!!!!
I was wondering such a nice WS example since very long time.
Now I am relaxed doing all these example.
I request to you,Pls give EJB 3.0 tutorial such a nice way.
Thanks in advance.
Hello – I preferably should suggest, impressed with your site. I had no trouble navigating through all the tabs and so guidance had been genuinely easy to access. I came across what I hoped for very quickly all the way. Plus extremely good. Would most likely appreciate it in the event you add forums or something, it becomes much easier a fantastic way for your consumers to work together. Fine job..