*
The moose likes Web Services and the fly likes WSDL question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Web Services
Bookmark "WSDL question" Watch "WSDL question" New topic
Author

WSDL question

jite eghagha
Ranch Hand

Joined: Oct 06, 2006
Posts: 127
I use a Sun App Server, and NetBeans IDE. I created a simple web service.

@WebService()
public class BasisPlusWS{

@WebMethod
public String[] getRecordById(@WebParam(name = "Str") String Str)
{
DataBase DB = new DataBase();
String [] resultSet = DB.getRecordById(Str);
return resultSet;
}

@WebMethod
public String[] getAllProjectTitles()
{
DataBase DB = new DataBase();
String [] resultSet = DB.getAllProjectTitles();
return resultSet;
}

@WebMethod
public String [] getAllProjectTasksByID(@WebParam(name = "Str") String Str) {
DataBase DB = new DataBase();
String [] resultSet = DB.getAllProjectTasksByID(Str);
return resultSet;
}

@WebMethod
public String [] getAllAreas() {
DataBase DB = new DataBase();
String [] resultSet = DB.getAllAreas();
return resultSet;
}

@WebMethod
public String [] getAllProjectNumbers() {
DataBase DB = new DataBase();
String [] resultSet = DB.getAllProjectNumbers();
return resultSet;
}

@WebMethod
public String [] getAreaByID(@WebParam(name = "Str") String Str) {
DataBase DB = new DataBase();
String [] resultSet = DB.getAreaByID(Str);
return resultSet;
}

}
And here's there question,
why doesn't my WSDL mention "String []" or "String".
How does a client know what parameters to send or recieve? (i cut the WSDL short)

<?xml version="1.0" encoding="UTF-8"?><definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://BasisPlus/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://BasisPlus/" name="BasisPlusWSService">
<types>
<xsd:schema>
<xsd:import namespace="http://BasisPlus/" schemaLocation="http://Jackrussell.nwrc.cr.usgs.gov:8080/BasisPlus/BasisPlusWSService/__container$publishing$subctx/WEB-INF/wsdl/BasisPlusWSService_schema1.xsd" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"/>
</xsd:schema>
</types>
<message name="getRecordById">
<part name="parameters" element="tns:getRecordById"/>
</message>
<message name="getRecordByIdResponse">
<part name="parameters" element="tns:getRecordByIdResponse"/>
</message>
<message name="getAllProjectTitles">
<part name="parameters" element="tns:getAllProjectTitles"/>
</message>
<message name="getAllProjectTitlesResponse">
<part name="parameters" element="tns:getAllProjectTitlesResponse"/>
</message>
<message name="getAllProjectTasksByID">
<part name="parameters" element="tns:getAllProjectTasksByID"/>
</message>
<message name="getAllProjectTasksByIDResponse">
<part name="parameters" element="tns:getAllProjectTasksByIDResponse"/>
</message>
<message name="getAllAreas">
<part name="parameters" element="tns:getAllAreas"/>
</message>
<message name="getAllAreasResponse">
<part name="parameters" element="tns:getAllAreasResponse"/>
</message>
<message name="getAllProjectNumbers">
<part name="parameters" element="tns:getAllProjectNumbers"/>
</message>
<message name="getAllProjectNumbersResponse">
<part name="parameters" element="tns:getAllProjectNumbersResponse"/>
</message>
<message name="getAreaByID">
<part name="parameters" element="tns:getAreaByID"/>
</message>
<message name="getAreaByIDResponse">
<part name="parameters" element="tns:getAreaByIDResponse"/>
</message>


Is there some part of the process that i missed ?
[ October 12, 2006: Message edited by: jite eghagha ]
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by jite eghagha:
why doesn't my WSDL mention "String []" or "String".


In order to be "language independent" you can't tell the other side what the data should be translated to - thats what conventions are for. So any data that the WSDL will be talking about is XML data - nothing else. And XML doesn't support arrays - because it doesn't have to. A sequence of identical elements does the trick.

Originally posted by jite eghagha:
How does a client know what parameters to send or recieve? (i cut the WSDL short)


The String array returned by "getRecordById" is actually transported in the "getRecordByIdResponse" message. "tns:getRecordByIdResponse" defines the data that the message carries. The definition for "tns:getRecordByIdResponse" can be found in: http://Jackrussell.nwrc.cr.usgs.gov:8080/BasisPlus/BasisPlusWSService/__container$publishing$subctx/WEB-INF/wsdl/BasisPlusWSService_schema1.xsd

So that file must be available to the client. Then the client will use its own conventions to convert the data found in "tns:getRecordByIdResponse" to something that is suitable in the host language. If the language is Java and the SOAP stack uses the standard XML->Java conversion conventions the data will be converted to a String[].

The same principles apply to each of the Request and Reply messages. Each WebMethod will have a matching Request Message. A Reply message is only necessary when the WebMethod has a return value.
jite eghagha
Ranch Hand

Joined: Oct 06, 2006
Posts: 127
thanks alot !

What would you recommend i use as a return type:

#1
If i am returning data that consists of three distinct strings
e.g. 1 ProjectNumber, 1 ProjectTile, (multiple)Task Discriptions, (multiple) SubTask Discriptions.

#2
If i am returning a list of similar elements
e.g (multiple) ProjectNumbers

List, String [], or dataSet ?
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by jite eghagha:
What would you recommend


You aren't going to like it - but you did ask for my opinion.
Design the web service for what it is - a document exchange.

  • Identify the documents you need to exchange.
  • Design the XML documents and capture the design in XML Schema.
  • Define the endpoint that exchanges the documents.
  • Create a WSDL based on this design using the XML Schema.
  • Use a WSDL-to-Java tool to generate the Java Server (and optionally Client) Stubs.


  • Patterns and Strategies for Building Document-Based Web Services
    That is really the only way that you can ensure that the Web-service definition is clean and clear (i.e. client-friendly), free of any accidental structures and complexities imposed by the brute-force object-to-(hierarchical) XML conversion. "Web Service by annotation" was a feature that J2EE vendors wanted so that they could feature-compete with .NET. It wasn't added because its a better way of working. It's great for creating a quick "proof of concept", so that you can delay learning the nitty-gritty of web services just a little bit longer. However an interoperable production web service should be designed WSDL-first. Just because "Web Service by annotation" is easier, doesn't make it a best practice.

    3.4.1 Designing the Interface

    3.7 Handling XML Documents in a Web Service
    4.3 Designing XML-Based Applications

    Some XML-tools will contain features that should make the process of designing the necessary XML Schemas and WSDL a lot easier.

    BTW: when using Java-to-WSDL don't return Java-specific data types like List (even a date can cause trouble). There is no guarantee that the other side has an equivalent structure and even a Java-client generated from the WSDL may not use the same type!
    [ October 12, 2006: Message edited by: Peer Reynders ]
    jite eghagha
    Ranch Hand

    Joined: Oct 06, 2006
    Posts: 127
    thank you,

    now that i've gotten dealing with Objects out of the way, i'll begin learning WSDL to java and core XML for data exchange.

    I've got some reading to do this weekend.
     
     
    subject: WSDL question