Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9090815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:27:47+00:00 2026-06-16T22:27:47+00:00

I have problem with return simple String[] in JAX-WS . I have an @WebMethod:

  • 0

I have problem with return simple String[] in JAX-WS .
I have an @WebMethod:

    public String[] getUserInfo() {
        MessageContext mc = wsContext.getMessageContext();
        HttpSession session = ((javax.servlet.http.HttpServletRequest) mc.get(MessageContext.SERVLET_REQUEST)).getSession();
        String username = (String) session.getAttribute("username");
        String[] userInfo = new String[4];
        Session hibSess = HibernateUtil.getSessionFactory().openSession();
        hibSess.beginTransaction();
        String query = "select id, login, email, active from User as user where user.login ='Mrl'";
        Query queryResult = hibSess.createQuery(query);
        java.util.List user = queryResult.list();
        int i;
        int j;
        Object object = null;
        for (i = 0; i < user.size(); i++) {
            Object[] obj = (Object[]) user.get(i);
            for (j = 0; j < obj.length; j++) {
                userInfo[j] = obj[j].toString();
            }
        }
        /* Here is the moment when I check the array on server side - it's fine */
        System.out.println("US:"+user.size() + ", userInfo length" +userInfo.length+"\n"+userInfo[0]
                +"\n"+userInfo[1]+"\n"+userInfo[2]+"\n"+userInfo[3]);
        return userInfo;
    }

The array should have four elements. And on server it has four elements, they contain corract data.

When I try to get that Array on my client I don’t get any error. I just get an one-element array which is empty.

Here is the client code:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "getUserInfo")
public class GetUserInfo {
}

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "getUserInfoResponse", propOrder = {
    "_return"
})
public class GetUserInfoResponse {
@XmlElement(name = "return")
protected String[] _return;

public String[] getReturn() {
    return _return;
}

public void setReturn(String[] value) {
    this._return = value;
}

}

And for running the client I use:

SimpleWebService proxy = new SimpleWebServiceService().getSimpleWebServicePort();
    ((BindingProvider)proxy).getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY,true);
proxy.connect();
String[] userArray = proxy.getUserInfo();

server wsdl fragment:

<message name="getUserInfo"/>
<message name="getUserInfoResponse">
    <part xmlns:ns2="http://jaxb.dev.java.net/array" name="return" type="ns2:stringArray"/>
</message>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T22:27:49+00:00Added an answer on June 16, 2026 at 10:27 pm

    You could use List instead of arrays, this is the default in jax-ws.

    But you could use a custom XmlAdapter if your really insist in using that array type, that adapts between a type jax-ws can understand and a custom new one.

    You need to annotate:

    @XmlElement(name = "return")
    @XmlJavaTypeAdapter(StringArrayXmlAdapter.class)
    protected String[] _return;
    

    StringArrayXmlAdapter:

    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;
    
    import javax.xml.bind.annotation.adapters.XmlAdapter;
    
    public class StringArrayXmlTypeAdapter extends
            XmlAdapter<List<String>, String[]> {
        @Override
        public List<String> marshal(String[] arg) throws Exception {
            return new ArrayList<String>(Arrays.asList(arg));
        }
    
        @Override
        public String[] unmarshal(List<String> arg) throws Exception {
            return arg.toArray(new String[] {});
        }
    }
    

    I didn’t try it with arrays, so i can’t guarantee that is works exactly like this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with these simple classes: public class Thread { public string
I have simple JAX-RS server application: @GET @Path(/getImage/{key}) @Produces(image/jpeg) public final BufferedImage getImageResource(@PathParam(key) String
Possible Duplicate: XML Carriage return encoding I have a class with some simple string
I have problem understanding what the return fibonacci( number-1 ) + fibonacci( number-2 )
I have a problem with Json formating returned from .ASMX I need to return
I have a problem when using jsonp to API HTTPS website. it will return
I have an odd problem when using the return result of a function and
I have an interesting problem, which is a function that returns a Dictionary<String,HashSet<String>> .
I have a problem with a simple C# web service from a sample. This
I have a simple class Role: @Entity @Table (name = ROLE) public class Role

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.