How to call web services by java web application?

Answered

I create a java web service by the URL as below:

IntelliJ IDEA 开发 WebService | 比利鱼

IntelliJ IDEA 开发 WebService

http://www.biliyu.com/article/986.html

package example;public class HelloWorld {
public String sayHelloWorldFrom(String from) {
String result = "Hello, world, from " + from;
System.out.println(result);
return result;
}
}

http://localhost:8080/services

the address content as below:

And now... Some Services

  • AdminService (wsdl)
    • AdminService
  • Version (wsdl)
    • getVersion
  • SOAPMonitorService (wsdl)
    • publishMessage
  • HelloWorld (wsdl)
    • sayHelloWorldFrom

How do I call HelloWorld's sayHelloWorldForm function with the parameter string?

I successfully create a web service, but I do not know how to create a web application(web service client) to call the web service. I find some articles that are conceptual descriptions.

Does somebody have the example of calling web service?

0
4 comments
Avatar
Permanently deleted user

I try to create a web service client project for the URL of "http://localhost:8080/services/HelloWorld?wsdl". I modify the code in main function as below:

 

package example;
public class HelloWorldClient {
public static void main(String[] argv) {
try {

HelloWorldServiceLocator locator = new HelloWorldServiceLocator();
HelloWorld_PortType portType = locator.getHelloWorld();

String str = portType.sayHelloWorldFrom("My friend");

System.out.println("str=" + str);

//Activator service = locator.get();
// If authorization is required
//((HelloWorldSoapBindingStub)service).setUsername("user3");
//((HelloWorldSoapBindingStub)service).setPassword("pass3");
// invoke business method
//service.businessMethod();
} catch (javax.xml.rpc.ServiceException ex) {
ex.printStackTrace();
}
catch (java.rmi.RemoteException ex) {
ex.printStackTrace();
}
}
}

But when I run the WebServiceClient and set some breakpoints at main function. But it does not work. I open chrome and input the URL of "http://localhost:8081/". There is nothing to show. No breakpoint is triggered.

I use CentOS in Virtual Box. These are the screenshots of the configuration and the web browser(firefox). 

Does somebody know how to solve this problem?





0
Avatar
Permanently deleted user

I also do the same work in Windows 10. These are my complete source code: Does somebody help me to solve this problem?

 

TestWebService.zip 

https://onedrive.live.com/embed?cid=FBEB6373D9321A7F&resid=FBEB6373D9321A7F%21787476&authkey=AOU3rhSTFePTLc8 

TestWebServiceClient.zip 

https://onedrive.live.com/embed?cid=FBEB6373D9321A7F&resid=FBEB6373D9321A7F%21787475&authkey=AF3syG4klfj0Cn0 

0
Avatar
Permanently deleted user

When I use glassfsish and JavaFx project with webservice client. The problem is solved. But it means the webservice client use apachaxis may have bugs.

0

Hello,

Could you please clarify the issue? Why do you run client code using Tomcat? If you run "HelloWorldClient" as application it connects to server and "str=Hello, world, from hi" is returned.

 

0

Please sign in to leave a comment.