Hi,
I just started the book Java Web Service: Up and Running.
I have been trying to get the very first example working, although i have used Eclipse Galileo, rather than compiling from the prompt.
However, when I try to run the client program, I keep getting an "Undefined port type" error. As Im very new to web services, I have been unable to pin-point the actual error in the code.
I include the WSDL and the code for the Client, in the hope that someone can give me a few pointers.
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://ts" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://ts" xmlns:intf="http://ts" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
<wsdl:types>
<schema elementFormDefault="qualified" targetNamespace="http://ts" xmlns="http://www.w3.org/2001/XMLSchema">
<element name="getTimeAsString">
<complexType/>
</element>
<element name="getTimeAsStringResponse">
<complexType>
<sequence>
<element name="getTimeAsStringReturn" type="xsd:string"/>
</sequence>
</complexType>
</element>
<element name="getTimeAsElapsed">
<complexType/>
</element>
<element name="getTimeAsElapsedResponse">
<complexType>
<sequence>
<element name="getTimeAsElapsedReturn" type="xsd:long"/>
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>
<wsdl:message name="getTimeAsStringRequest">
<wsdl:part element="impl:getTimeAsString" name="parameters"/>
</wsdl:message>
<wsdl:message name="getTimeAsElapsedResponse">
<wsdl:part element="impl:getTimeAsElapsedResponse" name="parameters"/>
</wsdl:message>
<wsdl:message name="getTimeAsElapsedRequest">
<wsdl:part element="impl:getTimeAsElapsed" name="parameters"/>
</wsdl:message>
<wsdl:message name="getTimeAsStringResponse">
<wsdl:part element="impl:getTimeAsStringResponse" name="parameters"/>
</wsdl:message>
<wsdl:portType name="TimeServerImpl">
<wsdl:operation name="getTimeAsString">
<wsdl:input message="impl:getTimeAsStringRequest" name="getTimeAsStringRequest"/>
<wsdl:output message="impl:getTimeAsStringResponse" name="getTimeAsStringResponse"/>
</wsdl:operation>
<wsdl:operation name="getTimeAsElapsed">
<wsdl:input message="impl:getTimeAsElapsedRequest" name="getTimeAsElapsedRequest"/>
<wsdl:output message="impl:getTimeAsElapsedResponse" name="getTimeAsElapsedResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="TimeServerImplSoapBinding" type="impl:TimeServerImpl">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getTimeAsString">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getTimeAsStringRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getTimeAsStringResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getTimeAsElapsed">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getTimeAsElapsedRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getTimeAsElapsedResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="TimeServerImplService">
<wsdl:port binding="impl:TimeServerImplSoapBinding" name="TimeServerImpl">
<wsdlsoap:address location="http://localhost:8080/WebServiceProject/services/TimeServerImpl"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
package ts;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import java.net.URL;
import java.util.Iterator;
class TimeClient {
public static void main(String args[ ]) throws Exception {
URL url = new URL(" http://localhost:8080/WebServiceProject/services/TimeServerImpl?wsdl");
// Qualified name of the service:
// 1st arg is the service URI
// 2nd is the service name published in the WSDL
QName qname = new QName("http://ts", "TimeServerImplService");
// Create, in effect, a factory for the service.
Service service = Service.create(url, qname);
// Extract the endpoint interface, the service "port".
try {
TimeServer eif = service.getPort(TimeServer.class);
} catch (Exception e){
e.printStackTrace();
}
// System.out.println(eif.getTimeAsString());
// System.out.println(eif.getTimeAsElapsed());
}
}
Edited by: Mondariz on Aug 3, 2009 1:30 AM