?
Solved

Web Service Java help

Posted on 2004-04-26
7
Medium Priority
?
469 Views
Last Modified: 2011-10-03
How do I fix the i == 2 section?

package dii;

import javax.xml.rpc.Call;
import javax.xml.rpc.Service;
import javax.xml.rpc.JAXRPCException;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceFactory;
import javax.xml.rpc.ParameterMode;
import java.io.*;
import java.lang.*;

public class TransactionClient {

      
    private static String qnameService = "TransactionService";
    private static String qnamePort = "TransactionIF";

    private static String BODY_NAMESPACE_VALUE = "urn:Foo";
    private static String ENCODING_STYLE_PROPERTY = "javax.xml.rpc.encodingstyle.namespace.uri";
    private static String NS_XSD = "http://www.w3.org/2001/XMLSchema";
    private static String URI_ENCODING = "http://schemas.xmlsoap.org/soap/encoding/";

    public static void main(String[] args) {
            
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("1. Open Account");
            System.out.println("2. Deposit");
            System.out.println("3. Withdrawl");
            System.out.println("0. Exit");
            System.out.println("Selection: ");

            try {
            ServiceFactory factory = ServiceFactory.newInstance();
            Service service = factory.createService(new QName(qnameService));

            QName port = new QName(qnamePort);

            Call call = service.createCall(port);
            call.setTargetEndpointAddress("http://152.15.21.56:8080/webservice/transaction");

            call.setProperty(Call.SOAPACTION_USE_PROPERTY, new Boolean(true));
            call.setProperty(Call.SOAPACTION_URI_PROPERTY, "");
            call.setProperty(ENCODING_STYLE_PROPERTY, URI_ENCODING);
            QName QNAME_TYPE_STRING = new QName(NS_XSD, "string");
                  QName QNAME_TYPE_DOUBLE = new QName(NS_XSD, "double");
                  QName QNAME_TYPE_INTEGER = new QName(NS_XSD, "int");
            call.setReturnType(QNAME_TYPE_STRING);
                  
                  int i;
                  while ( (i = Integer.parseInt(reader.readLine())) != 0)
                  {

                        if (i == 1)
                        {
                              System.out.println("Enter name: ");
                              String userName = reader.readLine();

                              System.out.println("Enter Deposit: ");
                              String initDeposit = reader.readLine();
                              
                              
                              call.setOperationName(new QName(BODY_NAMESPACE_VALUE, "openAcct"));
                              call.addParameter("String_1", QNAME_TYPE_STRING, ParameterMode.IN);
                              call.addParameter("double_2", QNAME_TYPE_DOUBLE, ParameterMode.IN);
                              Object[] params = new Object[2];
                              params[0] = userName;
                              params[1] = new Double(initDeposit);

                              String result = (String)call.invoke(params);
                              System.out.println(result);
                        }
                        else if (i == 2)
                        {
                              System.out.println("Enter Account: ");
                              Object account = reader.readLine();
                              
                              System.out.println("Enter Deposit: ");
                              Object deposit = reader.readLine();
                              
                              call.setOperationName(new QName(BODY_NAMESPACE_VALUE, "deposit"));
                              call.addParameter("int_1", QNAME_TYPE_INTEGER, ParameterMode.IN);
                              call.addParameter("double_2", QNAME_TYPE_DOUBLE, ParameterMode.IN);
                              Object[] params = { account, deposit };

                              String result = (String)call.invoke(params);
                              System.out.println(result);
                        }
                        else if (i == 3)
                        {
                              System.out.println("Enter Account: ");
                              Object account = reader.readLine();
                              //int accountNum = Integer.parseInt(account);

                              System.out.println("Enter Withdrawl: ");
                              Object withdraw = reader.readLine();
                              //double withdrawCon = Double.parseDouble(withdraw);

                              call.setOperationName(new QName(BODY_NAMESPACE_VALUE, "withdraw"));
                              call.addParameter("int_1", QNAME_TYPE_INTEGER, ParameterMode.IN);
                              call.addParameter("double_2", QNAME_TYPE_DOUBLE, ParameterMode.IN);
                              Object[] params = { account, withdraw };

                              String result = (String)call.invoke(params);
                              System.out.println(result);
                        }
                  }
                reader.close();
                  System.exit(0);
            } catch      (Exception ex) {
            ex.printStackTrace();
        }
    }
}
0
Comment
Question by:Azrael37
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 92

Expert Comment

by:objects
ID: 10916341
what exactly is the problem?
0
 
LVL 9

Accepted Solution

by:
mmuruganandam earned 2000 total points
ID: 10916347
You have to create the object and then assign to the parameters.  I have had these kind of similar problems when i started off with the webservices.

The following should work...

>>  Object[] params = { account, deposit };


Object[] params = new Object[2];
params[0] = new Integer(account);
params[1] = new Double(deposit);

This would help... try this out...


Regards,
Muruga
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10916359
even you have to do the same for i == 3 section too

Otherwise... that won't work too
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

Author Comment

by:Azrael37
ID: 10916360
Just testing, and it worked.
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10916364
change your i == 3 section too

it has the same problem
0
 
LVL 8

Expert Comment

by:william_jwd
ID: 10916375
try this,

else if (i == 2)
                   {
                         System.out.println("Enter Account: ");
                         String account = reader.readLine();
                         Integer intAccount = new Integer(account);
                         
                         System.out.println("Enter Deposit: ");
                         String deposit = reader.readLine();
                         Double dblDeposit = new Double(deposit);
                         
                         call.setOperationName(new QName(BODY_NAMESPACE_VALUE, "deposit"));
                         call.addParameter("int_1", QNAME_TYPE_INTEGER, ParameterMode.IN);
                         call.addParameter("double_2", QNAME_TYPE_DOUBLE, ParameterMode.IN);
                         Object[] params = { intAccount, dblDeposit };

                         String result = (String)call.invoke(params);
                         System.out.println(result);
                    }
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10916381
easy points on my packet... thanx Azrael37.
0

Featured Post

Quick Cloud Training

Looking for some quick training on the cloud in 2 hours or less? Check out these how-to guides in AWS, Linux, OpenStack, Azure, and more!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
The viewer will learn how to implement Singleton Design Pattern in Java.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month10 days, 14 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question