サイドバーの壁紙
博主头像
tin博主等级

子の曰わく、我れ三人行なえば必ず我が師を得(う)。其の善き者を択びてこれに従う。其の善からざる者にしてこれを改む。

  • 累積執筆 72 記事
  • 累計作成 32 タグ
  • 累計受入 2 コメント

目 次CONTENT

記事目次

SOAPサービスの疎通確認

tin
tin
2024-08-15 / 0 コメント / 0 いいね! / 470 読み / 1,518 文字

LinuxサーバでSOAPの疎通確認を行うためには、SOAPリクエストを送信してレスポンスを確認する方法があります。SOAPはHTTPをプロトコルとして使用するため、HTTPリクエストを送信するツールやライブラリを使用するのが一般的です。以下は、いくつかの方法を紹介します。

1. curl コマンドを使用する

curl -X POST http://example.com/soap-endpoint \
     -H "Content-Type: text/xml; charset=utf-8" \
     -H "SOAPAction: アクション名" \
     -d '<?xml version="1.0" encoding="utf-8"?>
         <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                           xmlns:ex="http://example.com/">
             <soapenv:Header/>
             <soapenv:Body>
                 <ex:SomeRequest>
                     <ex:agr0>value0</ex:arg0>
                     <ex:agr1>value1</ex:arg1>
                 </ex:SomeRequest>
             </soapenv:Body>
         </soapenv:Envelope>'

下記の項目(下線内容のみで良い)は実際のwsdlとxsdファイル内容に従って編集する必要があります。

  • curl -X POST http://example.com/soap-endpoint -----wsdlファイルsoap:address locationの定義内容
  • SOAPAction: アクション名 ---------------------------------wsdlファイルoperation name=またはaction=の定義内容(action優先)
  • xmlns:ex="http://example.com/”-----------------------------xsdファイルtargetNamespace=の定義内容
  • <ex:agr0>value0</ex:arg0> -----------------xsdファイルのoperation名に関する入力パラメータ定義内容(出現頻度、ネーム、タイプ)のネームを指す
  • <ex:agr1>value0</ex:arg1>

exについて
ex は、XML名前空間でのプレフィックス(接頭辞)です。プレフィックスは、XMLドキュメント内で名前空間を簡単に参照するために使用される略称です。プレフィックスそのものには特定の意味はありませんが、名前空間のURIを識別するために使われます
xmlns:ex="http://example.com/": 名前空間 http://example.com/ex プレフィックスに関連付けます。
ex:SomeRequestex:Parameter: これらの要素は、名前空間 http://example.com/ に属しています。

2. curlの動作確認

# 実行コマンド(IPで地域を特定するSOAPサービス)
tin@ubuntu01:~$ curl -X POST http://wsgeoip.lavasoft.com/ipservice.asmx \
     -H "Content-Type: text/xml; charset=utf-8" \
     -H "SOAPAction: http://lavasoft.com/GetIpLocation" \
     -d '<?xml version="1.0" encoding="utf-8"?>
         <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                           xmlns:ex="http://lavasoft.com/">
             <soapenv:Header/>
             <soapenv:Body>
                 <ex:SomeRequest>
                     <ex:sIp>172.217.31.132</ex:sIp>
                 </ex:SomeRequest>
             </soapenv:Body>
         </soapenv:Envelope>'

# Response結果
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetIpLocationResponse xmlns="http://lavasoft.com/"><GetIpLocationResult>&lt;GeoIP&gt;&lt;Country&gt;US&lt;/Country&gt;&lt;State&gt;CA&lt;/State&gt;&lt;/GeoIP&gt;</GetIpLocationResult></GetIpLocationResponse></soap:Body></soap:Envelope>tin@ubuntu01:~$ 
tin@ubuntu01:~$ 
tin@ubuntu01:~$ 

3. 上記動作コマンドの素材元(※のところ)

3-1. wsdlファイル

# wsdlファイルの抜粋
 <wsdl:service name="GeoIPService">
    <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">&lt;b&gt;A web service which performs GetIpAddress Lookups.&lt;/b&gt;</wsdl:documentation>
    <wsdl:port name="GeoIPServiceSoap" binding="tns:GeoIPServiceSoap">
      <soap:address location="http://wsgeoip.lavasoft.com/ipservice.asmx" /> ※
    </wsdl:port>
    <wsdl:port name="GeoIPServiceSoap12" binding="tns:GeoIPServiceSoap12">
      <soap12:address location="http://wsgeoip.lavasoft.com/ipservice.asmx" />
    </wsdl:port>
    <wsdl:port name="GeoIPServiceHttpGet" binding="tns:GeoIPServiceHttpGet">
      <http:address location="http://wsgeoip.lavasoft.com/ipservice.asmx" />
    </wsdl:port>
    <wsdl:port name="GeoIPServiceHttpPost" binding="tns:GeoIPServiceHttpPost">
      <http:address location="http://wsgeoip.lavasoft.com/ipservice.asmx" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

3-2. xsdファイル(xsdファイルが見つからないため、JAVAソースに代わる)

# JAVAの抜粋
public interface GeoIPServiceSoap {


    /**
     * <br/>Get Country and State XML String for a given ip address in x.x.x.x format<br/><br/>Parameter:GetIpAddress address &nbsp;&nbsp;&nbsp;&nbsp;<b>Type:String</b><br/><br/>Return:format in XML < GeoIP >< Country >US< /Country >< State >PA< /State >< /GeoIP > &nbsp;&nbsp;&nbsp;&nbsp;<b>Type:String</b>
     * 
     * @param sIp
     * @return
     *     returns java.lang.String
     */
    @WebMethod(operationName = "GetIpLocation", action = "http://lavasoft.com/GetIpLocation") ※
    @WebResult(name = "GetIpLocationResult", targetNamespace = "http://lavasoft.com/")
    @RequestWrapper(localName = "GetIpLocation", targetNamespace = "http://lavasoft.com/", className = "com.lavasoft.GetIpLocation")
    @ResponseWrapper(localName = "GetIpLocationResponse", targetNamespace = "http://lavasoft.com/", className = "com.lavasoft.GetIpLocationResponse") ※
    public String getIpLocation(
        @WebParam(name = "sIp", targetNamespace = "http://lavasoft.com/") ※
        String sIp);

豆知識:
@WebParam(name = “sIp”, targetNamespace = “http://lavasoft.com/”)String sIpについて、
上記はクライアント側のクラスですが、サービス側のインターフェースクラスの中でString sIp(@WebParamがない)を定義する場合、
サービスをリクエストする際に、パラメータ名は「sIp」ではなく、「arg0」にする必要があります。
xsdファイル中のパラメータも「arg0」になります。

4. 参考:wget コマンド

wget --header="Content-Type: text/xml; charset=utf-8" \
     --header="SOAPAction:アクション名" \
     --post-data='<?xml version="1.0" encoding="utf-8"?>
         <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                           xmlns:ex="http://example.com/">
             <soapenv:Header/>
             <soapenv:Body>
                 <ex:SomeRequest>
                     <ex:agr0>value0</ex:arg0>
                     <ex:agr1>value1</ex:arg1>
                 </ex:SomeRequest>
             </soapenv:Body>
         </soapenv:Envelope>' \
     http://example.com/soap-endpoint
0
  • 0

コメント欄