2012-11-22 16 views
5

Javaプロジェクトでは、jax-wsとwsdlを使用してWebサービスクライアントを作成しました。要求は有効なXMLですが、この特定のSOAP呼び出しで必要な接頭辞がありません。現在、私は手動でxmlns = {@ javax.xml.bind.annotation.XmlNs(prefix = "gen"、namespaceURI = "http:// schemas ...")})をpackage-info.javaクラスに追加することでこれを解決していますパッケージ情報が自動的に作成され、何らかの理由でソースが再度生成された場合、私の解決策が上書きされるため、これが最善の解決策ではないと感じます。jax-wsを使用してSOAPリクエストのプレフィックスがありません

私の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> 

編集:追加接頭辞が2番目の例のnamespacedeclarationには、最初はそこにありましたが、何とか失われましたが、c/pのコード。

+5

XMLパーサーまたはSOAP実装の場合、両方の要求が同一である必要があります。接頭辞はXMLでは意味を持ちません。重要なのは名前空間と名前のローカル部分です。 2番目の例では、接頭辞 'gen'は実際には無効な名前空間にバインドされていません。 'xmlns:gen'を' xmlns'だけに使用するつもりなら、両方のリクエストは同じように扱われなければなりません。 –

答えて

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

は手動でクラスファイルにpackage-info.javaをコンパイルする必要があります。

0

スキーマからクラスを生成する場合は、JAXBバインディングファイルを追加することができます。

このanswerには、スキーマのデフォルト名前空間の接頭辞を指定するファイルのテンプレートがあります。

次に、ジェネレーションツールを使用するときに追加のバインディングファイルを指定します。

EDIT

一つの例は、使用するファイルは次のようになります。

<?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プラグインを使用することを忘れないでください。

関連する問題