hey,
i am working on a web services (WS) program. i have a method in the server that reads text file and store every line of text in to a string array.
on the client side, when i call the method it shows me that the value being retuned is String but not a string array (String[])
help why am i unable to return array from the server to the client


thank you!!!!

SERVER

import javax.jws.Oneway;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import java.io.*;
import java.lang.String;


@WebService()
public class Customer {


    /**
     * Web service operation
     */
    @WebMethod(operationName = "openFile")
    public String[] openFile(@WebParam(name = "fileName")
    String fileName) {

        int num = 0;
        int i =0;
        String str="";
        String[] name=new String[200];


        try  {
            BufferedReader bufeinp = new BufferedReader( new FileReader("customers/"+fileName+".txt"));
            while ((str = bufeinp.readLine()) !=null){
              name[i] =str;
              i++;
              ++num;
          }
          bufeinp.close();
        }
        catch(IOException e)
        {
            System.err.println("Exception: " + e.getMessage());
            System.exit(1);
        }

     return name;

    }
}

CLIENT

private cust.CustomerService service = new cust.CustomerService();
    private cust.Customer port = service.getCustomerPort();
//this part gives me error
         String[] array = port.displayNames();

Recommended Answers

All 2 Replies

I'm not familiar with WS, but what's the connection between displayNames() that you call on the client and openFile that you define on the server?

im a sorry i displayed wrong code for the client.

this is how the client actually should look like

private cust.CustomerService service = new cust.CustomerService();
    private cust.Customer port = service.getCustomerPort();
//this part gives me error
         String[] array = port.openFile(fileName)

thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.