3

Axis2 / Tomcat / Apache サーバーでホストされている、Java で記述された Web サービスがあります。クライアント ソフトウェアは C# で記述されています。

私は java2wsdl が wsdl ファイルを生成する方法でいくつかの厄介な問題を抱えていました。初期の段階で頭痛の種になりましたが、この問題で完全に困惑しています。

基本的に何が起こっているかというと、クライアントは Web サービスに問題がないことを確認し、完全に有効な (または少なくとも、私には有効に見える) パラメータ付きの SOAP リクエストを送信します。

サーバーでは、正しい Web メソッドが実行されますが、パラメーターはすべて null です。私の Web サービスはこれを検出し、クライアントが受信して完全に理解できる応答を作成します。

私の推測では、Axis2 はどこかで顔をしかめていると思いますが、java2wsdl で頭痛の種を抱えていたことを考えると、必要なのは wsdl ファイルを変更することだけかもしれません。

wsdl ファイルは次のとおりです。

    <?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:axis2="http://stws/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:ns0="http://stws/xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://stws/">
    <wsdl:types>
        <xs:schema xmlns:ns="http://stws/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://stws/xsd">
            <xs:element name="GetGroups">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element minOccurs="0" name="serialcode" nillable="true" type="xs:string"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="GetGroupsResponse">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="ns0:Group"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:complexType name="Group">
                <xs:sequence>
                    <xs:element minOccurs="0" name="ID" type="xs:int"/>
                    <xs:element minOccurs="0" name="Name" nillable="true" type="xs:string"/>
                </xs:sequence>
            </xs:complexType>
            <xs:element name="GetMessages">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element minOccurs="0" name="serialcode" nillable="true" type="xs:string"/>
                        <xs:element maxOccurs="unbounded" minOccurs="0" name="groupids" type="xs:int"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="GetMessagesResponse">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="ns0:Message"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:complexType name="Message">
                <xs:sequence>
                    <xs:element minOccurs="0" name="date" nillable="true" type="xs:string"/>
                    <xs:element minOccurs="0" name="group" type="xs:int"/>
                    <xs:element minOccurs="0" name="messageID" type="xs:int"/>
                    <xs:element minOccurs="0" name="text" nillable="true" type="xs:string"/>
                </xs:sequence>
            </xs:complexType>
        </xs:schema>
    </wsdl:types>
    <wsdl:message name="GetMessagesRequest">
        <wsdl:part name="parameters" element="ns0:GetMessages"/>
    </wsdl:message>
    <wsdl:message name="GetMessagesResponse">
        <wsdl:part name="parameters" element="ns0:GetMessagesResponse"/>
    </wsdl:message>
    <wsdl:message name="GetGroupsRequest">
        <wsdl:part name="parameters" element="ns0:GetGroups"/>
    </wsdl:message>
    <wsdl:message name="GetGroupsResponse">
        <wsdl:part name="parameters" element="ns0:GetGroupsResponse"/>
    </wsdl:message>
    <wsdl:portType name="MyProjectPortType">
        <wsdl:operation name="GetMessages">
            <wsdl:input message="axis2:GetMessagesRequest" wsaw:Action="urn:GetMessages"/>
            <wsdl:output message="axis2:GetMessagesResponse" wsaw:Action="urn:GetMessagesResponse"/>
        </wsdl:operation>
        <wsdl:operation name="GetGroups">
            <wsdl:input message="axis2:GetGroupsRequest" wsaw:Action="urn:GetGroups"/>
            <wsdl:output message="axis2:GetGroupsResponse" wsaw:Action="urn:GetGroupsResponse"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="MyProjectSOAP11Binding" type="axis2:MyProjectPortType">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
        <wsdl:operation name="GetMessages">
            <soap:operation soapAction="urn:GetMessages" style="document"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="GetGroups">
            <soap:operation soapAction="urn:GetGroups" style="document"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:binding name="MyProjectSOAP12Binding" type="axis2:MyProjectPortType">
        <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
        <wsdl:operation name="GetMessages">
            <soap12:operation soapAction="urn:GetMessages" style="document"/>
            <wsdl:input>
                <soap12:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap12:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="GetGroups">
            <soap12:operation soapAction="urn:GetGroups" style="document"/>
            <wsdl:input>
                <soap12:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap12:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:binding name="MyProjectHttpBinding" type="axis2:MyProjectPortType">
        <http:binding verb="POST"/>
        <wsdl:operation name="GetMessages">
            <http:operation location="MyProject/GetMessages"/>
            <wsdl:input>
                <mime:content type="text/xml" part="GetMessages"/>
            </wsdl:input>
            <wsdl:output>
                <mime:content type="text/xml" part="GetMessages"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="GetGroups">
            <http:operation location="MyProject/GetGroups"/>
            <wsdl:input>
                <mime:content type="text/xml" part="GetGroups"/>
            </wsdl:input>
            <wsdl:output>
                <mime:content type="text/xml" part="GetGroups"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="MyProject">
        <wsdl:port name="MyProjectSOAP11port_http" binding="axis2:MyProjectSOAP11Binding">
            <soap:address location="http://localhost:8080/axis2/services/MyProject"/>
        </wsdl:port>
        <wsdl:port name="MyProjectSOAP12port_http" binding="axis2:MyProjectSOAP12Binding">
            <soap12:address location="http://localhost:8080/axis2/services/MyProject"/>
        </wsdl:port>
        <wsdl:port name="MyProjectHttpport" binding="axis2:MyProjectHttpBinding">
            <http:address location="http://localhost:8080/axis2/services/MyProject"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

リクエストとレスポンスの例を次に示します。

リクエスト:

<?xml version='1.0' encoding='utf-8'?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soap:Body>
    <GetGroups xmlns="http://stws/xsd">
      <serialcode>123456-654321</serialcode>
    </GetGroups>
  </soap:Body>
</soap:Envelope>

応答

<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
    <GetGroupsResponse xmlns="http://stws/xsd">
      <return>
        <ID>-101</ID>
        <name>ERROR: Empty Serial</name>
      </return>
    </GetGroupsResponse>
  </soapenv:Body>
</soapenv:Envelope>

何がうまくいかないのか誰にも分かりませんか?

応答のエラー メッセージは、要求の serialcode パラメータが空または null の場合にのみ送信できるため、Axis2 がパラメータを読み取る方法に問題があると推測されます。

================================================== ==========

これを修正する方法:

これは、私がこの問題をどのように解決したかについての詳細情報を求める Aldo の要求に応えたものです。

この修正が機能する理由はわかりません。おそらく、Axis2 のバグか何かである可能性があります。いずれにせよ、問題の原因が自分のセットアップによるものなのか、それとも他の何かによるものなのかはわからないため、YMMV です。私が言えるのは、次のことを行うことで、すべてが機能し始めたということだけです。

とにかく、自動生成された WSDL ファイルは、Web 要求とそのパラメーターの複雑な要素の型を作成します。これは、パラメーターが文字列や整数などの単純な型だけであっても同様です。私が行ったことは、パラメーターの正しい単純型タグ (「serialcode」や「date-string」など) を作成してから、WSDL ファイル内の他の場所にある複合型への参照を単純型への参照に置き換えることでした。

以下に例を示します。

自動生成された WSDL メソッドとパラメーター

<!--Requests-->    
<wsdl:message name="RegisterClientRequest">
    <wsdl:part name="parameters" element="ns0:RegisterClient"/>
</wsdl:message>
<wsdl:message name="GetGroupsRequest">
    <wsdl:part name="parameters" element="ns0:GetGroups"/>
</wsdl:message>

<!--Parameters-->
<xs:element name="RegisterClient">
    <xs:complexType>
        <xs:sequence>
           <xs:element minOccurs="0" name="serialcode" nillable="true" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>
<xs:element name="GetGroups">
    <xs:complexType>
        <xs:sequence>
            <xs:element minOccurs="0" name="serialcode" nillable="true" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
 </xs:element>

基本的に、自動生成されたパラメーターを破棄して単純型を作成する必要があります。次に、「request」タグを「element」ではなく「type」を使用するように変更し、新しく作成した単純型を使用します。

変更/修正された WSDL

<!--Requests-->    
<wsdl:message name="RegisterClientRequest">
    <wsdl:part name="parameters" type="ns0:SerialCode"/>
</wsdl:message>
<wsdl:message name="GetGroupsRequest">
    <wsdl:part name="parameters" type="ns0:SerialCode"/>
</wsdl:message>

<!--Parameters-->
<xs:simpleType name="SerialCode">
    <xs:restriction base="xs:string"/>
</xs:simpleType>

明らかに、実際のパラメーターが何であるかによって異なります。私の場合、それらはすべて文字列や整数などの標準的な単純型です。複数のパラメーターを渡す場合は、自動生成された要素を保持して、要素が「xs:string」またはその性質の型属性を単に含めるのではなく、単純な型を参照するようにする必要があるかもしれません。 .

申し訳ありませんが、これについてこれ以上明確にすることはできませんが、前に述べたように、なぜこれが機能するのかわかりません。

最後に 1 つ: リクエスト タグの「要素」参照属性を削除すると、Axis2 ログでパーサーの警告が表示される場合があります。これまでのところ、これによって問題が発生することはありませんが、問題が発生した場合に備えて注意が必要です。

4

6 に答える 6

1

複雑な属性がある場合、これはどのように行うことができますか

 <xs:element name="getMyMenu">
            <xs:complexType>
                <xs:sequence>
                    <xs:element minOccurs="0" name="number" nillable="true" type="xs:string"/>
                    <xs:element minOccurs="0" name="var2" nillable="true" type="xs:string"/>
                    <xs:element minOccurs="0" name="var3" nillable="true" type="xs:string"/>
                    <xs:element minOccurs="0" name="var4" nillable="true" type="xs:string"/>
                </xs:sequence>
            </xs:complexType>
        </xs:element>

            <xs:complexType name="getMyMenu">
                <xs:sequence>
                    <xs:element minOccurs="0" name="number" nillable="true" type="xs:string"/>
                    <xs:element minOccurs="0" name="var2" nillable="true" type="xs:string"/>
                    <xs:element minOccurs="0" name="var3" nillable="true" type="xs:string"/>
                    <xs:element minOccurs="0" name="var4" nillable="true" type="xs:string"/>
                </xs:sequence>
            </xs:complexType>

そして、これを変更します

<wsdl:message name="getMyMenuRequest">
    <wsdl:part name="parameters" type="ns0:getUssdMenu"/>
</wsdl:message>

<wsdl:message name="getMyMenuRequest">
    <wsdl:part name="parameters" type="ns:getUssdMenu"/>
</wsdl:message>

それはそれである必要があります!それは私のためにそれをしました....

于 2010-11-04T08:06:09.457 に答える
1

私はこの問題を解決するために、自分の WSDL ファイルを調べ、可能な限り要素を対応する単純型に分解し、それに応じて XML 要素間の参照を更新しました。

なぜこれが機能するのかはわかりませんが、とにかく問題は解決しました。

于 2009-06-29T13:00:51.357 に答える
0

このようなリクエストを送信しようとしましたか?

<?xml version='1.0' encoding='utf-8'?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soap:Body>
    <request>
      <GetGroups xmlns="http://stws/xsd">
        <serialcode>123456-654321</serialcode>
      </GetGroups>
    </request>
  </soap:Body>
</soap:Envelope>

すべてのリクエストには、実際のリクエストパラメータの前にリクエストタグがあります。

于 2009-06-26T13:20:00.487 に答える
0

これを試してください: 123456-654321

パラメータタグに xmlns="" を入れます。私は同じ問題を抱えており、xmlnx なしでパラメーターを受け取るために何を変更できるかわかりません。

于 2009-08-24T15:34:11.347 に答える
0

これは単なる推測ですが、名前空間に問題がある可能性があります。wsdl のこの部分に注目すると、パラメーターには要素の "ns0" 名前空間がありますが、後で定義する操作では、"axis2" 名前空間を使用しているように見えます。Axis2 で生成されたすべての WSDL で、これら 2 つの名前空間は同じです。

<wsdl:message name="GetMessagesRequest">
    <wsdl:part name="parameters" element="ns0:GetMessages"/>
</wsdl:message>
<wsdl:message name="GetMessagesResponse">
    <wsdl:part name="parameters" element="ns0:GetMessagesResponse"/>
</wsdl:message>
<wsdl:message name="GetGroupsRequest">
    <wsdl:part name="parameters" element="ns0:GetGroups"/>
</wsdl:message>
<wsdl:message name="GetGroupsResponse">
    <wsdl:part name="parameters" element="ns0:GetGroupsResponse"/>
</wsdl:message>

<wsdl:portType name="MyProjectPortType">
    <wsdl:operation name="GetMessages">
        <wsdl:input message="axis2:GetMessagesRequest" wsaw:Action="urn:GetMessages"/>
        <wsdl:output message="axis2:GetMessagesResponse" wsaw:Action="urn:GetMessagesResponse"/>
    </wsdl:operation>
    <wsdl:operation name="GetGroups">
        <wsdl:input message="axis2:GetGroupsRequest" wsaw:Action="urn:GetGroups"/>
        <wsdl:output message="axis2:GetGroupsResponse" wsaw:Action="urn:GetGroupsResponse"/>
    </wsdl:operation>
</wsdl:portType>

他に確認できることは、java2wsdl から取得した wsdl が、axis2 によって生成されたものと同じであることを確認することです。services.xml の「useoriginalwsdl」のデフォルト設定を変更していない限り、これらの wsdl は「見た目」が異なる場合があります。Webサービスを正しく機能させるために手動でjava2wsdlを実行する必要はありませんでした...

したがって、基本的には、ブラウザでサービス URL にアクセスし、URL の末尾に ?wsdl を追加します...比較のために wsdl を取得する必要があります。

また、java2wsdl によって生成されたものではなく、サーバーの wsdl からクライアントにスタブを生成させます (最初に java2wsdl の wsdl を使用したと仮定します)。繰り返しになりますが、手動で生成された wsdl を誰かに渡す必要はありませんでした...彼らはサーバーから動的に生成された wsdl を消費するだけでした...

于 2009-06-16T13:54:38.337 に答える
0

別の修正があります。最終的に、IDE (Netbeans 6.8) に WSDL を生成させないと、Web サービスが機能することがわかりました。または、それを削除し、生成オプションのチェックを外して再デプロイすると、機能しました。

Netbeans で生成された WSDL とサーバーで生成された WSDL を比較すると、次の違いがあることに気付きました。

  • xmlns:ns0="http:///xsd"
  • wsdl:definitions タグの末尾にあるターゲット名前空間の末尾にスラッシュがありました
  • wsdl:message タグを構成する要素を選択するために使用される ns0

これらをすべて削除して再デプロイするとうまくいきました!

于 2010-03-04T00:36:58.890 に答える