Solved

Web Service Java help

Posted on 2004-04-26
7
463 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 500 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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

705 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