[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Web Service Java help

Posted on 2004-04-26
7
Medium Priority
?
479 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
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month20 days, 6 hours left to enroll

872 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