2012-09-03 22 views
9

でリクエストを処理できない私のWebサービスは、次のようにクライアントがSOAPボディに接頭辞を通過せずにWebサービスを呼び出しているとき、私のクライアントの要求を処理することができません。Webサービスは、SOAPボディ名前空間接頭辞を持っていない

<soap:Body> 
<GetPatientResultsRequest xmlns="http://urlA"> 
    <PatientIdentification> 
     <PersonCivilRegistrationIdentifier xmlns="http://UrlB"/> 
    </PatientIdentification> 
    <Period> 
    <From>2012-05-26</From> 
    <To>2012-06-26</To> 
    </Period> 
</GetPatientResultsRequest> 
</soap:Body> 

GetPatientResultsRequestなどに対応するJavaオブジェクトがnullであるというエラーが発生します。

ボディに接頭辞がない場合、デシリアライゼーションが適切に行われていないようです。私のWebサービスは、誰もが私はので、私のWebサービスは、すなわち接頭辞とし、なし(すべての種類のSOAPリクエストを取ることができることを何をすべきかを知らせることができますSOAPボディ

<soap:Body> 
<m:GetPatientResultsRequest xmlns:m="http://urlA"> 
    <PatientIdentification> 
     <PersonCivilRegistrationIdentifier xmlns="http://UrlB"/> 
    </PatientIdentification> 
    <Period> 
    <From>2012-05-26</From> 
    <To>2012-06-26</To> 
    </Period> 
</m:GetPatientResultsRequest> 
</soap:Body> 

のような接頭辞を持っているときにのみ応答することができます体)?私はJAX-WS(SOAP 1.1)

+0

あなたはどのクライアントを使用していますか? jaxws? – Cris

+1

2つの例が異なります。最初のケースでは、名前空間は 'GetPatientResultsRequest'と' PatientIdentification'、 'Period'、' From'と 'To'要素にあります。 2番目の例では、 'GetPatientResultsRequest'要素にしかありません。 –

+0

私は同じ問題に直面しています。この問題を解決できるかどうか教えてください... –

答えて

8

Webサービスを使用しています

は、あなたがそれを呼び出すために従わなければならない契約を定義します。投稿した例のメッセージの1つのみが、その契約と一致するので、一方が動作し、もう一方は動作しません。

最初のメッセージでは、(ラッパーのxmlns属性のために)デフォルトの名前空間を定義しました。そして、それを宣言しないプレフィックスのないすべての要素は、親から継承するため同じ名前空間にあります。

2番目のメッセージでは、明示的なプレフィックス宣言があり、ラッパーのみがその名前空間にあり、他の要素は名前空間になく、(xmlns属性がないために)親からデフォルトのものを継承しません。

私が最初に言ったように、Webサービスは契約を定義しています。 クライアントからの不正なメッセージを受け入れるようにサービスを変更するのではなく、正しいメッセージを送信するようにクライアントを変更する方が理にかなっています。あなたのWebサービスとクライアントのJAX-WSのアノテーションtargetNamespace値を使用する必要があなたの要素の名前空間を制御するために

ここでは、ターゲットの名前空間を変更したときのコードとメッセージの形式の違いを確認する例を示します。

<?xml version="1.0" encoding="utf-8"?> 
<wsdl:definitions 
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
xmlns:tns="http://tempuri.org" 
xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
targetNamespace="http://tempuri.org" 
name="CalculatorWS"> 
    <wsdl:types> 
    <xs:schema targetNamespace="http://tempuri.org"> 
     <xs:element name="add" type="tns:add" /> 
     <xs:element name="addInput" type="tns:addInput" /> 
     <xs:element name="addResponse" type="tns:addResponse" /> 
     <xs:element name="addOutput" type="tns:addOutput" /> 
     <xs:complexType name="add"> 
     <xs:sequence> 
      <xs:element name="addInput" type="tns:addInput" /> 
     </xs:sequence> 
     </xs:complexType> 
     <xs:complexType name="addInput"> 
     <xs:sequence> 
      <xs:element name="a" type="xs:int" /> 
      <xs:element name="b" type="xs:int" /> 
     </xs:sequence> 
     </xs:complexType> 
     <xs:complexType name="addResponse"> 
     <xs:sequence> 
      <xs:element name="addOutput" type="tns:addOutput" /> 
     </xs:sequence> 
     </xs:complexType> 
     <xs:complexType name="addOutput"> 
     <xs:sequence> 
      <xs:element name="result" type="xs:int" /> 
     </xs:sequence> 
     </xs:complexType> 
    </xs:schema> 
    </wsdl:types> 
    <wsdl:message name="add"> 
    <wsdl:part name="parameters" element="tns:add" /> 
    </wsdl:message> 
    <wsdl:message name="addResponse"> 
    <wsdl:part name="parameters" element="tns:addResponse" /> 
    </wsdl:message> 
    <wsdl:portType name="CalculatorWS"> 
    <wsdl:operation name="add"> 
     <wsdl:input message="tns:add" /> 
     <wsdl:output message="tns:addResponse" /> 
    </wsdl:operation> 
    </wsdl:portType> 
    <wsdl:binding name="CalculatorWSPortBinding" type="tns:CalculatorWS"> 
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" /> 
    <wsdl:operation name="add"> 
     <soap:operation soapAction="http://tempuri.org/add" /> 
     <wsdl:input> 
     <soap:body use="literal" /> 
     </wsdl:input> 
     <wsdl:output> 
     <soap:body use="literal" /> 
     </wsdl:output> 
    </wsdl:operation> 
    </wsdl:binding> 
    <wsdl:service name="CalculatorWSService"> 
    <wsdl:port name="CalculatorWSPort" binding="tns:CalculatorWSPortBinding"> 
     <soap:address location="http://localhost:8080/WebServices/CalculatorWS" /> 
    </wsdl:port> 
    </wsdl:service> 
</wsdl:definitions> 

これは以下のようにメッセージを定義しています:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
     xmlns:tem="http://tempuri.org"> 
    <soapenv:Body> 
     <tem:add> 
     <addInput> 
      <a>?</a> 
      <b>?</b> 
     </addInput> 
     </tem:add> 
    </soapenv:Body> 
</soapenv:Envelope> 

と:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
     xmlns:tem="http://tempuri.org"> 
    <soapenv:Body> 
     <tem:addResponse> 
     <addOutput> 
      <result>?</result> 
     </addOutput> 
     </tem:addResponse> 
    </soapenv:Body> 
</soapenv:Envelope> 

はラッパーの名前空間接頭辞を参照してください。私は、このための基本的なWSDLを使用しますか?これは、要素がhttp://tempuri.org名前空間で宣言されており、他の要素が名前空間になく、名前空間にないためです。

名前空間からすべての要素を削除することもできます。WSDLからのターゲット名前空間をストリップと、それはこのように見えるように取得する:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soapenv:Body> 
     <add> 
     <addInput> 
      <a>?</a> 
      <b>?</b> 
     </addInput> 
     </add> 
    </soapenv:Body> 
</soapenv:Envelope> 

と::

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soapenv:Body> 
     <addResponse> 
     <addOutput> 
      <result>?</result> 
     </addOutput> 
     </addResponse> 
    </soapenv:Body> 
</soapenv:Envelope> 

接頭辞なしでこの新しいWSDLのようなメッセージに対応します

<?xml version="1.0" encoding="utf-8"?> 
<wsdl:definitions 
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
name="CalculatorWS"> 
    <wsdl:types> 
    <xs:schema> 
     <xs:element name="add" type="add" /> 
     <xs:element name="addInput" type="addInput" /> 
     <xs:element name="addResponse" type="addResponse" /> 
     <xs:element name="addOutput" type="addOutput" /> 
     <xs:complexType name="add"> 
     <xs:sequence> 
      <xs:element name="addInput" type="addInput" /> 
     </xs:sequence> 
     </xs:complexType> 
     <xs:complexType name="addInput"> 
     <xs:sequence> 
      <xs:element name="a" type="xs:int" /> 
      <xs:element name="b" type="xs:int" /> 
     </xs:sequence> 
     </xs:complexType> 
     <xs:complexType name="addResponse"> 
     <xs:sequence> 
      <xs:element name="addOutput" type="addOutput" /> 
     </xs:sequence> 
     </xs:complexType> 
     <xs:complexType name="addOutput"> 
     <xs:sequence> 
      <xs:element name="result" type="xs:int" /> 
     </xs:sequence> 
     </xs:complexType> 
    </xs:schema> 
    </wsdl:types> 
    <wsdl:message name="add"> 
    <wsdl:part name="parameters" element="add" /> 
    </wsdl:message> 
    <wsdl:message name="addResponse"> 
    <wsdl:part name="parameters" element="addResponse" /> 
    </wsdl:message> 
    <wsdl:portType name="CalculatorWS"> 
    <wsdl:operation name="add"> 
     <wsdl:input message="add" /> 
     <wsdl:output message="addResponse" /> 
    </wsdl:operation> 
    </wsdl:portType> 
    <wsdl:binding name="CalculatorWSPortBinding" type="CalculatorWS"> 
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" /> 
    <wsdl:operation name="add"> 
     <soap:operation soapAction="http://tempuri.org/add" /> 
     <wsdl:input> 
     <soap:body use="literal" /> 
     </wsdl:input> 
     <wsdl:output> 
     <soap:body use="literal" /> 
     </wsdl:output> 
    </wsdl:operation> 
    </wsdl:binding> 
    <wsdl:service name="CalculatorWSService"> 
    <wsdl:port name="CalculatorWSPort" binding="CalculatorWSPortBinding"> 
     <soap:address location="http://localhost:8080/WebServices/CalculatorWS" /> 
    </wsdl:port> 
    </wsdl:service> 
</wsdl:definitions> 

この場合。

は今、両方のWSDLにwsimport.exeを使用すると、あなたは私が最初に話していたターゲット名前空間、このからすなわち変更表示されます。これに

@WebService(name = "CalculatorWS", targetNamespace = "http://tempuri.org") 
public interface CalculatorWS { 
    @WebMethod(action = "http://tempuri.org/add") 
    @WebResult(name = "addOutput", targetNamespace = "") 
    @RequestWrapper(localName = "add", targetNamespace = "http://tempuri.org", className = "your.pack.age.Add") 
    @ResponseWrapper(localName = "addResponse", targetNamespace = "http://tempuri.org", className = "your.pack.age.AddResponse") 
    public AddOutput add(
     @WebParam(name = "addInput", targetNamespace = "") 
     AddInput addInput); 
} 

@WebService(name = "CalculatorWS", targetNamespace = "") 
public interface CalculatorWS { 
    @WebMethod(action = "http://tempuri.org/add") 
    @WebResult(name = "addOutput", targetNamespace = "") 
    @RequestWrapper(localName = "add", targetNamespace = "", className = "your.pack.age.Add") 
    @ResponseWrapper(localName = "addResponse", targetNamespace = "", className = "your.pack.age.AddResponse") 
    public AddOutput add(
     @WebParam(name = "addInput", targetNamespace = "") 
     AddInput addInput); 
} 

が制御をtargetNamespaceとし、メッセージの表示方法を制御します。

関連する問題