在使用默认 Java 1.6 java.xml.ws API 生成的 WSDL 中缺少 SOAP 方法参数 [英] Missing SOAP method parameters in generated WSDL using the default Java 1.6 java.xml.ws API

查看:24
本文介绍了在使用默认 Java 1.6 java.xml.ws API 生成的 WSDL 中缺少 SOAP 方法参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了一个简单的网络服务,它有一个方法接受一个字符串并返回一条包含输入参数的消息.

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);

当我启动应用程序时,会在 http://localhost:8080/hello?wsdl

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>

在客户端,我可以访问我的网络服务,也可以访问方法 sayMyName(String name)

At the client side I can access my webservice and also get access to the method sayMyName(String name)

我的问题是我无法在客户端为函数提供名称参数.我假设生成的 WSDL 是错误的,因为它不包含参数信息.

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.

有人可以向我解释我在这里做错了什么,为什么 WSDL 不包含参数参数?

Can someone explain to me what I'm doing wrong here, why does the WSDL contain no parameter argument?

推荐答案

你说的参数是在schemaLocation"属性中指定的.见下文.

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>

这样就可以查看"http://localhost:8080/hello?xsd=中的参数信息1".

如果你想从 ?wsdl 为 java 生成客户端,

If you want to generate client for java from ?wsdl,

wsimport -keep http://localhost:8080/hello?wsdl

你知道-keep"的意思是用源代码生成"

you know "-keep" means "generate with source code"

您可以获得一组客户端代码.

You can get a set of client code.

我有另一个建议

如果您想在 WSDL 中包含 XSD 以使birt"等工具理解 WSDL,

If you want to include XSDs to WSDL to make the tools like "birt" understand WSDL,

尝试使用如下所示的内联模式(没有 schemeLocation)生成 WSDL,

Try to generate WSDL with inline schemas (without schemeLocation) like below,

wsgen -cp . com.product.mobile.webapp.soap.WSHello -wsdl -inlineSchemas

将创建WSHelloService.wsdl"文件.

"WSHelloService.wsdl" file will be created.

在 WSHello 类中编辑 @WebService 注释,如下所示.

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;
    }

}

重新启动服务器并使用您的访问http://localhost:8080/hello?wsdl"工具.

Restart the server and access "http://localhost:8080/hello?wsdl" with your tool.

希望能帮到你.

这篇关于在使用默认 Java 1.6 java.xml.ws API 生成的 WSDL 中缺少 SOAP 方法参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆