I have a sample question,can i return a Jframe in a method defined in a jaxws webservice implementation class.if soo give me steps simple steps onlt or keywords,
i ve tried for example:

import java.awt.*;
import javax.jws.WebService;
import javax.jws.WebMethod;
    @WebService(serviceName="frameService", portName="framePort", name="frame",wsdlLocation = "WEB-INF/primary.wsdl")
    @BindingType(value=javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_MTOM_BINDING)
    public class frameserver implements Serializable{
    @WebMethod
    public Object send()
    {

     Object o=new Object();
     JFrame f=new JFrame("khaled");
     JLabel l=new JLabel("hiba");
     f.add(l);
     o=(JFrame)f;
     return o;

    }

    public static void main(String[] args)
    {
    }
    }`

i ve created a jax ws web service and do this but i m receiving an error.pls tell me if possible sending jframe using this way or no .wish somebody would answer my question ive been searching for couple of months without finding a solution to my problem
thanks,regards

Dani AI

Generated

Short answer for : do not try to return a JFrame (or any Swing component) from a JAX‑WS method. A normal Java method returns an in‑JVM object reference; a web service must serialize the return value so it can cross the network. JAX‑WS uses XML/JAXB binding for that, and Swing components are neither JAXB‑friendly nor intended to be marshaled. As noted, services should provide data, not UI.

A practical approach you can apply immediately:

  1. Define small data transfer objects (POJOs) that hold only the fields the client needs. Make them JAXB‑friendly (default no‑arg constructor and getters/setters, or annotate with JAXB annotations).
  2. Expose a web method that returns an array or a simple wrapper containing those DTOs (for example RecordDTO[] or a Records wrapper).
  3. On the client, reconstruct the GUI (JFrame/JTable) from those DTOs.

Example DTO (minimal):

@XmlRootElement
public class RecordDTO {
  private String id;
  private String name;
  public RecordDTO() {}
  public String getId() { return id; }
  public void setId(String id) { this.id = id; }
  public String getName() { return name; }
  public void setName(String name) { this.name = name; }
}

Client-side: turn the DTO array into a table model and show it in a JFrame:

DefaultTableModel m = new DefaultTableModel(new String[]{"ID","Name"}, 0);
for (RecordDTO r : records) {
  m.addRow(new Object[]{ r.getId(), r.getName() });
}
JTable table = new JTable(m);

Troubleshooting tips: check the server stacktrace for JAXB exceptions (missing no‑arg constructor, illegal annotations), inspect the generated WSDL to see the exposed types, and run wsgen if needed. If both ends are Java and you insist on shipping object graphs, RMI or manual serialization into a byte[] is possible but fragile, insecure, and not interoperable. Best practice: return small, stable data objects from the service and build the UI on the client.

Recommended Answers

All 5 Replies

NO!
Anyway why would you want to do something like that?

bcs as a client is requesting certain data from my database remotely,so i want to return certain records from my database to present it in a jtable so i want to return a jfraame.but in a normal method not used in a webservice i can return a jframe,why using jaxws i cant do so??

Well you got your facts wrong. Your Swing application should query service, service should process request and return data in some for of object. This object is then taken over by Swing and showed to user. Because you just want to show some data, example user details (username, real name, DOB, email address etc) you not gone push the whole java framework from your webservice. Besides recipient of the request doesn't have to be necessary Java application

apreciate ur response,
yes for sure the client side is not a java applications.i gave an example only,i can use a server side program as jsp or servlet to call the webservice,but i want to know as kind of curiosity is it possible to return a jtable for example in this web service that i m calling.bcs normally i programed many small applications and returned a jframe,but this is not the case in jaxws,i want to know only why??

For once you are sevice provider you provide responce to request and do not add any unnecessary extras.Secondly why would you want to push an elephant object that will take XYZ amount of time when you can push small ant and recepient. Lastly you do not know what version of Java recipient may run, it may be older or newer then what you are using to create response and may not have some of the stuff you reffering in your object because it was added in version after it or it was removed for some reason.

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.