1 /*
2  * @(#) $Id: EchoClient1.java,v 1.2 2003/07/08 08:13:52 pankaj Exp $
3  *
4  * Copyright (c) 2002-03 by Pankaj Kumar (http://www.pankaj-k.net). 
5  * All rights reserved.
6  *
7  * The license governing the use of this file can be found in the 
8  * root directory of the containing software.
9  */
10import java.io.BufferedReader;
11import java.io.InputStreamReader;
12
13import javax.xml.namespace.QName;
14import javax.xml.rpc.ServiceFactory;
15import javax.xml.rpc.Service;
16import javax.xml.rpc.Call;
17
18public class EchoClient1 {
19    public static void main(String [] args) throws Exception {
20        String epAddr = "http://localhost:8080/axis/services/StringEchoPort1";
21
22        String wsdlAddr = "file:echo.wsdl";
23        String nameSpaceUri = "http://www.pankaj-k.net/jsbook/examples/";
24        String svcName = "StringEchoService1";
25        String portName = "StringEchoPort1";
26
27        java.net.URL wsdlUrl = new java.net.URL(wsdlAddr);
28        ServiceFactory svcFactory = ServiceFactory.newInstance();
29        QName svcQName = new QName(nameSpaceUri, svcName);
30        Service svc = svcFactory.createService(wsdlUrl, svcQName);
31
32        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
33        System.out.print("Enter Username: ");
34        System.out.flush();
35        String username = br.readLine();
36        System.out.print("Enter Password: ");
37        System.out.flush();
38        String password = br.readLine();
39
40        Call call = (Call) svc.createCall();
41
42        call.setTargetEndpointAddress(epAddr);
43        call.setOperationName( new QName(nameSpaceUri, "echo") );
44        call.setPortTypeName( new QName(nameSpaceUri, portName) );
45
46        call.setProperty(Call.USERNAME_PROPERTY, username);
47        call.setProperty(Call.PASSWORD_PROPERTY, password);
48
49        Object arg = "Hi, How are you?";
50        System.out.println("sending: " + arg );
51        String res = (String) call.invoke(new Object[] {arg});
52        System.out.println("received: " + res );
53    }
54}
55