问题
I have implemented a simple webservice that has one method that takes a String and returns a message containing the input parameter.
package com.product.mobile.webapp.soap;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.ParameterStyle;
import javax.jws.soap.SOAPBinding.Style;
import javax.jws.soap.SOAPBinding.Use;
@WebService
@SOAPBinding(style = Style.DOCUMENT, use = Use.LITERAL, parameterStyle = ParameterStyle.WRAPPED)
public class WSHello {
@WebMethod
public String sayMyName(@WebParam(name = "name", mode = Mode.IN) String name) {
return "Hello, ... " + name;
}
}
I'm publishing this endpoint like that:
WSHello wsHello = new WSHello();
String wsHelloEndpoint = "http://localhost:8080/hello";
Endpoint.publish(wsHelloEndpoint, wsHello);
When I start the application the following WSDL is created and available under http://localhost:8080/hello?wsdl
<?xml version="1.0" encoding="UTF-8"?><!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.4-b01. --><!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.4-b01. --><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://soap.webapp.mobile.product.at/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://soap.webapp.mobile.product.at/" name="WSHelloService">
<types>
<xsd:schema>
<xsd:import namespace="http://soap.webapp.mobile.product.at/" schemaLocation="http://localhost:8080/hello?xsd=1"></xsd:import>
</xsd:schema>
</types>
<message name="sayMyName">
<part name="parameters" element="tns:sayMyName"></part>
</message>
<message name="sayMyNameResponse">
<part name="parameters" element="tns:sayMyNameResponse"></part>
</message>
<portType name="WSHello">
<operation name="sayMyName">
<input wsam:Action="http://soap.webapp.mobile.product.at/WSHello/sayMyNameRequest" message="tns:sayMyName"></input>
<output wsam:Action="http://soap.webapp.mobile.product.at/WSHello/sayMyNameResponse" message="tns:sayMyNameResponse"></output>
</operation>
</portType>
<binding name="WSHelloPortBinding" type="tns:WSHello">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"></soap:binding>
<operation name="sayMyName">
<soap:operation soapAction=""></soap:operation>
<input>
<soap:body use="literal"></soap:body>
</input>
<output>
<soap:body use="literal"></soap:body>
</output>
</operation>
</binding>
<service name="WSHelloService">
<port name="WSHelloPort" binding="tns:WSHelloPortBinding">
<soap:address location="http://localhost:8080/hello"></soap:address>
</port>
</service>
</definitions>
At the client side I can access my webservice and also get access to the method sayMyName(String name)
My problem is that I can't provide the name parameter to the function at the client. I'm assuming the generated WSDL is wrong since it does not contain the parameter information.
Can someone explain to me what I'm doing wrong here, why does the WSDL contain no parameter argument?
回答1:
The parameter you said is specified in "schemaLocation" attribute. see below.
<xsd:import namespace="http://soap.webapp.mobile.product.at/" schemaLocation="http://localhost:8080/hello?xsd=1"></xsd:import>
So you can check the parameter information in the "http://localhost:8080/hello?xsd=1".
If you want to generate client for java from ?wsdl,
wsimport -keep http://localhost:8080/hello?wsdl
you know "-keep" means "generate with source code"
You can get a set of client code.
I have another suggestion,
If you want to include XSDs to WSDL to make the tools like "birt" understand WSDL,
Try to generate WSDL with inline schemas (without schemeLocation) like below,
wsgen -cp . com.product.mobile.webapp.soap.WSHello -wsdl -inlineSchemas
"WSHelloService.wsdl" file will be created.
Edit @WebService annotation in WSHello class like below.
@WebService(wsdlLocation="WSHelloService.wsdl")
@SOAPBinding(style = Style.DOCUMENT, use = Use.LITERAL, parameterStyle = ParameterStyle.WRAPPED)
public class WSHello {
@WebMethod
public String sayMyName(@WebParam(name = "name", mode = Mode.IN) String name) {
return "Hello, ... " + name;
}
}
Restart the server and access "http://localhost:8080/hello?wsdl" with your tool.
hope it helps.
回答2:
Okay so I finally found out how to get it working, basically I added the following annotation to my @WebService
class:
@SOAPBinding(style = SOAPBinding.Style.RPC)
Full example:
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.xml.ws.BindingType;
@WebService
@BindingType(value = "http://java.sun.com/xml/ns/jaxws/2003/05/soap/bindings/HTTP/")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public class WSHello {
@WebMethod
public String sayMyName(@WebParam(name = "name") String name) {
return "Hello, ... " + name;
}
}
来源:https://stackoverflow.com/questions/39768971/missing-soap-method-parameters-in-generated-wsdl-using-the-default-java-1-6-java