Webservice mit eigener WSDL deployen

Nud3l

Mitglied
Hallo,

Ich habe folgendes Problem. Ich habe einen Webservice erzeugt, den ich aus einer bereitgestellten WSDL implementiert habe. Nun möchte ich beim Ausrollen, dass der Webservice die bereitgestellte WSDL nimmt und nicht sich eine eigene WSDL zusammenbaut.

Ich habe keine Ahnung, wie ich das meinem Service beibringen kann hat einer eine Idee?
 
ich nutze JAX-WS, java1.6 auf einem Glassfish 2.1 als buildtool nutze ich maven.

Hmm werden sonst noch infos gebraucht? kann die pom hier posten oder die xmls oder eines der implementierten Webservises.
 
Hallo,

ich vermute mal, dass du einen Web-Service definieren möchtest, der einer gegebenen WSDL-Beschreibung entspricht und diese auch verwendet.

Hier mal ein kleines Beispiel für einen JAX-WS Web-Service der eingegebenes WSDL Dokument verwendet auf Basis von Glassfish 3.1.2 unter Eclipse 3.7 JEE.

Die web.xml müssen wir hierbei nicht anfassen... Glassfish erkennt die JAX-WS Annotations automatisch.

1) Dynamic Web Project erstellen
(de.tutorials.gf.web.training)
2) WSDL definieren: und unter WEB-INF/wsdl/calculator_v1.wsdl ablegen
XML:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<definitions
	xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
	xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy"
	xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
	xmlns:tns="http://ws.calc.tutorials.de/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
	xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ws.calc.tutorials.de/"
	name="Calculator">
	<types />
	<message name="computeSumOfRequest">
		<part name="arg0" type="xsd:int" />
		<part name="arg1" type="xsd:int" />
	</message>
	<message name="computeSumOfResponse">
		<part name="return" type="xsd:int" />
	</message>
	<portType name="Calculator">
		<operation name="computeSumOf" parameterOrder="arg0 arg1">
			<input wsam:Action="http://ws.calc.tutorials.de/Calculator/computeSumOfRequest"
				message="tns:computeSumOfRequest" />
			<output wsam:Action="http://ws.calc.tutorials.de/Calculator/computeSumOfResponse"
				message="tns:computeSumOfResponse" />
		</operation>
	</portType>
	<binding name="CalculatorBinding" type="tns:Calculator">
		<soap:binding transport="http://schemas.xmlsoap.org/soap/http"
			style="rpc" />
		<operation name="computeSumOf">
			<soap:operation soapAction="" />
			<input>
				<soap:body use="literal" namespace="http://ws.calc.tutorials.de/" />
			</input>
			<output>
				<soap:body use="literal" namespace="http://ws.calc.tutorials.de/" />
			</output>
		</operation>
	</binding>
	<service name="Calculator">
		<port name="Calculator" binding="tns:CalculatorBinding">
			<soap:address location="http://localhost:44444/Calculator" />
		</port>
	</service>
</definitions>


3) Web-Service Interface definieren
Java:
package de.tutorials.calc.ws;

import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService
public interface Calculator {
	@WebMethod
	int computeSumOf(int a, int b);
}

4) Unsere WebService Implementierung definieren
Wichtig! Die WSDL-Location muss hierbei relativ zu WEB-INF/wsdl angegeben werden!
Java:
package de.tutorials.calc.ws;

import javax.jws.WebService;

@WebService(
			  serviceName="Calculator"
			, portName="Calculator"
			, endpointInterface="de.tutorials.calc.ws.Calculator"
			, wsdlLocation="calculator_v1.wsdl")
public class CalculatorWebService implements Calculator{

	@Override
	public int computeSumOf(int firstArg, int secondArg) {
		return firstArg+secondArg;
	}

}

5) Projekt auf glassfish deployen.

6) Anschließend kann man den Webservice (Beispielsweise über den in den Glassfish integrierten Tester) testen:
http://localhost:8080/de.tutorials.gf.web.training/Calculator?Tester

Ausgabe:
Code:
computeSumOf Method invocation


--------------------------------------------------------------------------------

Method parameter(s)
Type Value 
int 1 
int 2 

--------------------------------------------------------------------------------

Method returned
int : "3"
--------------------------------------------------------------------------------

SOAP Request

--------------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Header/>
    <S:Body>
        <ns2:computeSumOf xmlns:ns2="http://ws.calc.tutorials.de/">
            <arg0>1</arg0>
            <arg1>2</arg1>
        </ns2:computeSumOf>
    </S:Body>
</S:Envelope>


--------------------------------------------------------------------------------

SOAP Response

--------------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
        <ns2:computeSumOfResponse xmlns:ns2="http://ws.calc.tutorials.de/">
            <return>3</return>
        </ns2:computeSumOfResponse>
    </S:Body>
</S:Envelope>


--------------------------------------------------------------------------------

Schaut man sich via: http://localhost:8080/de.tutorials.gf.web.training/Calculator?wsdl
das WSDL an, sieht man, dass die angegebene Lokale WSDL Beschreibung verwendet wird:
XML:
<?xml version='1.0' encoding='UTF-8'?><!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is Metro/2.2-b13 (branches/2.2-6964; 2012-01-09T18:04:18+0000) JAXWS-RI/2.2.6-promoted-b20 JAXWS/2.2 svn-revision#unknown. --><definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ws.calc.tutorials.de/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ws.calc.tutorials.de/" name="Calculator">
	<types/>
	<message name="computeSumOfRequest">
		<part name="arg0" type="xsd:int"/>
		<part name="arg1" type="xsd:int"/>
	</message>
	<message name="computeSumOfResponse">
		<part name="return" type="xsd:int"/>
	</message>
	<portType name="Calculator">
		<operation name="computeSumOf" parameterOrder="arg0 arg1">
			<input wsam:Action="http://ws.calc.tutorials.de/Calculator/computeSumOfRequest" message="tns:computeSumOfRequest"/>
			<output wsam:Action="http://ws.calc.tutorials.de/Calculator/computeSumOfResponse" message="tns:computeSumOfResponse"/>
		</operation>
	</portType>
	<binding name="CalculatorBinding" type="tns:Calculator">
		<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/>
		<operation name="computeSumOf">
			<soap:operation soapAction=""/>
			<input>
				<soap:body use="literal" namespace="http://ws.calc.tutorials.de/"/>
			</input>
			<output>
				<soap:body use="literal" namespace="http://ws.calc.tutorials.de/"/>
			</output>
		</operation>
	</binding>
	<service name="Calculator">
		<port name="Calculator" binding="tns:CalculatorBinding">
			<soap:address location="http://localhost:8080/de.tutorials.gf.web.training/Calculator"/>
		</port>
	</service>
</definitions>

Gruß Tom
 
Zuletzt bearbeitet von einem Moderator:
Hey Danke,

Das hat mir geholfen hatte alles soweit richtig bis auf die Annotationen. Bei mir war die wsdlLocation falsch hatte immer WEB-INF/wsdl/ mit vorne dran gehabt. Zusätzlich musste ich noch den targetNamespace mit angeben aber dann hat es geklappt.
 
Zurück