5

在一个 Java 项目中,我使用 jax-ws 和 wsdl 创建了一个 Web 服务客户端。该请求是有效的 xml,但缺少此特定肥皂调用所需的前缀。目前我通过手动将 xmlns={@javax.xml.bind.annotation.XmlNs(prefix="gen", namespaceURI="http://schemas...")}) 添加到 package-info.java 类来解决这个问题但觉得这不是最好的解决方案,因为包信息是自动创建的,如果出于任何原因再次生成源,我的解决方案将被覆盖。

我怀疑我的 wsdl 中缺少某些东西。

这是wsdl:

<?xml version="1.0" encoding="UTF-8"?>
    <wsdl:definitions xmlns:tns="http://xmlns.example.com/1308658932768" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns0="http://schemas.triennium.com/Servicepunt/gen" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="Untitled" targetNamespace="http://xmlns.example.com/1308658932768">
        <wsdl:types>
        <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
     xmlns="http://schemas.triennium.com/Servicepunt/gen"
     targetNamespace="http://schemas.triennium.com/Servicepunt/gen"
     elementFormDefault="qualified"
     attributeFormDefault="unqualified">
            <xs:element name="CallInfo">
                <xs:complexType>
                    ...
                </xs:complexType>
            </xs:element>
            <xs:element name="ResponseStatus">
                <xs:complexType>
                    ...
                </xs:complexType>
            </xs:element>
            <xs:element name="Credentials">
                <xs:complexType>
                    ...
                </xs:complexType>
            </xs:element>
            <xs:element name="AuthenticateAannemerRequest">
                <xs:complexType>
                    ...
                </xs:complexType>
            </xs:element>
            <xs:element name="AuthenticateAannemerResponse">
                <xs:complexType>
                    ...
                </xs:complexType>
            </xs:element>
        </xs:schema>
    </wsdl:types>
    <wsdl:service name="WSDL_Generator.2.0.2">
        <wsdl:port name="AuthenticateAannemer.2.0.2" binding="tns:AuthenticateAannemer.2.0.2Binding">
            <soap:address location="http://10.11.2.12:2592"/>
        </wsdl:port>
    </wsdl:service>
    <wsdl:portType name="AuthenticateAannemer">
        <wsdl:operation name="AuthenticateAannemer">
            <wsdl:input message="tns:AuthenticateAannemerRequest"/>
            <wsdl:output message="tns:AuthenticateAannemerResponse"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="AuthenticateAannemer.2.0.2Binding" type="tns:AuthenticateAannemer">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="AuthenticateAannemer">
            <soap:operation style="document" soapAction="/AuthenticateAannemer.2.0.2/AuthenticateAannemer"/>
            <wsdl:input>
                <soap:body use="literal" parts="input"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal" parts="output"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:message name="AuthenticateAannemerRequest">
        <wsdl:part name="input" element="ns0:AuthenticateAannemerRequest"/>
    </wsdl:message>
    <wsdl:message name="AuthenticateAannemerResponse">
        <wsdl:part name="output" element="ns0:AuthenticateAannemerResponse"/>
    </wsdl:message>
</wsdl:definitions>

这是没有前缀的请求:

<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
        <AuthenticateAannemerRequest   xmlns="http://schemas.triennium.com/Servicepunt/gen">
            <CallInfo>
                <Customer>...</Customer>
                <Module>...</Module>
                <Version>...</Version>
            </CallInfo>
            <Credentials>
                <Username>...</Username>
                <Password>...</Password>
            </Credentials>
        </AuthenticateAannemerRequest>
    </S:Body>
</S:Envelope>

这是我想要的请求:

<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
        <gen:AuthenticateAannemerRequest xmlns:gen="http://schemas.triennium.com/Servicepunt/gen">
            <gen:CallInfo>
                <gen:Customer>...</Customer>
                <gen:Module>...</Module>
                <gen:Version>...</Version>
            </gen:CallInfo>
            <gen:Credentials>
                <gen:Username>...</Username>
                <gen:Password>...</Password>
            </gen:Credentials>
        </gen:AuthenticateAannemerRequest>
    </S:Body>
</S:Envelope>

编辑:在第二个示例中为命名空间声明添加了前缀,它是从那里开始的,但是在 c/p 代码时不知何故丢失了。

4

3 回答 3

0
@XmlRootElement(namespace = "http://schemas.triennium.com/Servicepunt/gen")
public class AuthenticateAannemerRequest implements Serializable {

    private CallInfo callInfo;
    private Credentials credentials;

    public AuthenticateAannemerRequest() {
    }

    @XmlElement(namespace = "http://schemas.triennium.com/Servicepunt/gen")
    public CallInfo getCallInfo() {
        return callInfo;
    }

    public void setCallInfo(CallInfo callInfo) {
        this.callInfo = callInfo;
    }

    @XmlElement(namespace = "http://schemas.triennium.com/Servicepunt/gen")
    public Credentials getCredentials() {
        return credentials;
    }

    public void setCredentials(Credentials credentials) {
        this.credentials = credentials;
    }
}
于 2013-03-28T09:17:38.643 回答
0

您需要手动将 package-info.java 编译到类文件中。

于 2014-08-22T21:40:16.273 回答
0

如果从模式生成类,则可以添加 JAXB 绑定文件。

查看此答案以获取该文件的模板,该模板指定架构默认命名空间的前缀。

然后在使用生成工具时指定附加的绑定文件。

编辑

您将使用的一个示例文件是:

<?xml version="1.0"?>
<jxb:bindings version="1.0"
              xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xmlns:namespace="http://jaxb2-commons.dev.java.net/namespace-prefix"
              xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd
              http://jaxb2-commons.dev.java.net/namespace-prefix http://java.net/projects/jaxb2-commons/sources/svn/content/namespace-prefix/trunk/src/main/resources/prefix-namespace-schema.xsd">

    <jxb:bindings>
        <jxb:schemaBindings>
            <jxb:package name="your-package-name-here" />
        </jxb:schemaBindings>
        <jxb:bindings>
            <namespace:prefix name="http://schemas.triennium.com/Servicepunt/gen" />
        </jxb:bindings>
    </jxb:bindings>
</jxb:bindings>

请记住在生成类时使用jaxb-commons插件。

于 2016-11-02T17:56:21.767 回答