public class SayHelloClient2
{
public static void Main (string[] args)
{
Try
{
String endpoint =
"Http://localhost:8080/Axis/HelloClient.jws";
Service service = new service ();
Call call = NULL;
Call = (call) Service.createcall ();
Call.setoperationname (New QName (
"Http://localhost:8080/Axis/HelloClient.jws",
"GetName"));
Call.settargetendpointaddress
(New Java.net.URL (endpoint));
string ret = (string) call.invoke (new object[]
{"Zhangsan"});
System.out.println ("return value is" + ret);
}
catch (Exception ex)
{
Ex.printstacktrace ();
}
}
}
Iii. writing dynamic proxy access Services
1, write the deployment of server-side programs, with the top dii mode, this time still use the top deployed helloclient
2, write Agent interface
public interface Helloclientinterface
Extends Java.rmi.Remote
{
public string GetName (string name)
Throws Java.rmi.RemoteException;
}
3, write and execute the client program Testhelloclient.java
public class Testhelloclient
{
public static void Main (string[] args)
{
Try
{
String Wsdlurl =
"HTTP://LOCALHOST:8080/AXIS/HELLOCLIENT.JWS?WSDL";
String NamespaceURI =
"Http://localhost:8080/Axis/HelloClient.jws";
String serviceName = "Helloclientservice";
String portname = "Helloclient";
Servicefactory servicefactory =
Servicefactory.newinstance ();
Service Afservice =
Servicefactory.createservice (New URL (Wsdlurl),
New QName (NamespaceURI, serviceName));
Helloclientinterface proxy = (helloclientinterface)
Afservice.getport (New QName (
NamespaceURI, PortName),
Helloclientinterface.class);
System.out.println
("Return value is" +proxy.getname ("John"));
}catch (Exception ex)
{
Ex.printstacktrace ();
}
}
}
Iv. Writing WSDD Publishing Web services, writing stub client Access Web services
1, write the service-side program Server,sayhello.java, compile Server.SayHello.java
Package server;
public class SayHello
{
public string GetName (string name)
{
Return "Hello" +name;
}
}
2. Preparation of Loghandler.java
Import Org.apache.Axis.AxisFault;
Import Org.apache.Axis.Handler;
Import Org.apache.Axis.MessageContext;
Import Org.apache.Axis.handlers.BasicHandler;
Import Java.util.Date;
public class Loghandler
Extends Basichandler
{
public void Invoke
(Messagecontext Msgcontext)
Throws Axisfault
{
/** Log an Access all time
We get invoked.
*/
try {
Handler Servicehandler
= Msgcontext.getservice ();
Integer numaccesses =
(Integer) servicehandler.getoption ("accesses");
if (numaccesses = null)
numaccesses = new Integer (0);
numaccesses = new Integer
(Numaccesses.intvalue () + 1);
Date date = new Date ();
String result =
Date + ": Service" +
Msgcontext.gettargetservice () +
"Accessed" + numaccesses + "time (s).";
Servicehandler.setoption
("accesses", numaccesses);
SYSTEM.OUT.PRINTLN (result);
catch (Exception e)
{
Throw Axisfault.makefault (e);
}
}
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.