Axis Getting Started (4)

zhaozj2021-02-16  110

Post your own web services service

1) Establishing your own Java files as follows: public class hellospace {? Public string echostring (String name)? {?? return name;?}} 2) Rename the file to helloservice.jws, Copy to D: / Tomcat 5.0 / WebAPPS / AXIS Directory 3) Start Tomcat4) Writing 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) {?????????? String endpoint = "http: // localhost: 8080 / axis / helloservice .jws "; ??????????????? SERVICE? service = new service (); ?????????? Call ???? call ??? = (CAL) 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.rr.println (e.tostring ()); ??????} ??}} 5) Run the client program, the effect is as follows:? Sent 'Hello!', Got ' Hello! 'Axis automatically positions files, compiles, and converts SOAP calls to Java calls to your service. 6) Is it very simple? Yes, but don't be happy too early, we have to pay attention to the following questions: ? JWS Web Services is just for simple web services, we can't use package in the service code, and the code is running

Compiled, less than the posting phase, you can't find any error message. We will discuss other methods that publish your own Web Services service later.

转载请注明原文地址:https://www.9cbs.com/read-10253.html

New Post(0)