Publish your own Web Services
1) Create your own Java file as follows:
Public class helloservice
{
? Public String echostring (string name)
? {
?? Return name;
?}
}
2) Rename the file helloservice. JWS and copy it to the D:/tomcat 5.0/webapps/axis directory.
3) start Tomcat
4) write the client code as follows:
Package com. hongsoft. test;
Import org. Apache. axis. Client. call;
Import org. Apache. axis. Client. Service;
Import javax. xml. namespace. QNAME;
Public class testclient
{
?? Public static void main (string [] ARGs ){
?????? Try {
?????????? String endpoint = "http: // localhost: 8080/axis/helloservice. JWS ";
????
?????????? Service? Service = new service ();
?????????? Call ???? Call ??? = (CALL) service. createcall ();
?????????? Call. settargetendpointaddress (New java.net. URL (endpoint ));??????????
?????????? Call. setoperationname (New QNAME ("echostring "));
??????????
?????????? String ret = (string) Call. Invoke (new object [] {"Hello! "});
?????????? System. Out. println ("sent 'Hello! ', Got' "+ RET + "'");
?????? } Catch (exception e ){
?????????? System. Err. println (E. tostring ());
?????? }
?? }
}
5) run the client program. The effect is as follows:
? Sent 'Hello! ', Got' hello! '
Axis can automatically locate files, compile, and convert soap calls into Java calls to your services.
6) Isn't it easy? Yes, but don't be too happy. We should pay attention to the following questions:
? JWS Web services are only used for simple web services. We cannot use a package in the service code, and the code is at runtime.
You cannot find any error message during compilation or release. We will discuss other methods for releasing your web services later.