PHP Velho Oeste 2024

サービスコンポーネントの、ウェブサービスとしての公開

SCA for PHP は、サービスコンポーネント内のアノテーションから WSDL を作成することができます。これにより、 ウェブサービスとして公開することが簡単にできるようになります。 WSDL の作成に必要な情報を SCA に与えるには、@binding.soap アノテーションを @service アノテーションの下に追加しなければなりません。 そこに、メソッドのパラメータおよび返り値をそれぞれ @param アノテーションおよび @return アノテーションで指定します。 これらのアノテーションを読み込むことで WSDL が作成され、 パラメータの順序や型が WSDL の <schema> セクションの内容を決定します。

SCA for PHP は、常に document/literal でラップされたコンポーネントの WSDL を作成します。これにより、ウェブサービスを公開します。注意してほしいのは、 これは、SCA コンポーネント以外のウェブサービスや 別の形式の WSDL で表されるウェブサービスの使用を妨げるものではないということです。

@param アノテーションで使用できるスカラー型は、 一般的な PHP のスカラー型である boolean、integer、float そして string です。これらは、WSDL において それぞれ同名の XML スキーマ型に変換されます。 以下の例は、ConvertedStockQuote コンポーネントが呼び出す StockQuote サービスをごく平凡に実装したもので、 string および float 型の使用法をご確認いただけます。

例1 StockQuote サービス

<?php

include "SCA/SCA.php";

/**
 * リモートの StockQuote ウェブサービスの土台となる実装
 *
 * @service
 * @binding.soap
 *
 */
class StockQuote {

    
/**
     * 指定したティッカーシンボルの株価を取得する
     *
     * @param string $ticker ティッカーシンボル
     * @return float 株価
     */
    
function getQuote($ticker) {
        return 
80.9;
  }
}
?>

このサービスの WSDL は、次のようになります (おそらく、サービスの場所は 'localhost' ではなく別のものになるでしょう)。

例2 作成された WSDL

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xsi:type="tDefinitions"
    xmlns:tns2="http://StockQuote" xmlns:tns="http://schemas.xmlsoap.org/wsdl/"
    xmlns:tns3="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" targetNamespace="http://StockQuote">
  <types>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
      targetNamespace="http://StockQuote">
      <xs:element name="getQuote">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="ticker" type="xs:string"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="getQuoteResponse">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="getQuoteReturn" type="xs:float"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:schema>
  </types>

  <message name="getQuoteRequest">
    <part name="getQuoteRequest" element="tns2:getQuote"/>
  </message>
  <message name="getQuoteResponse">
    <part name="return" element="tns2:getQuoteResponse"/>
  </message>
  <portType name="StockQuotePortType">
    <operation name="getQuote">
      <input message="tns2:getQuoteRequest"/>
      <output message="tns2:getQuoteResponse"/>
    </operation>
  </portType>
  <binding name="StockQuoteBinding" type="tns2:StockQuotePortType">
    <operation name="getQuote">
      <input>
        <tns3:body xsi:type="tBody" use="literal"/>
      </input>
      <output>
        <tns3:body xsi:type="tBody" use="literal"/>
      </output>
      <tns3:operation xsi:type="tOperation" soapAction=""/>
    </operation>
    <tns3:binding xsi:type="tBinding" transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
  </binding>
  <service name="StockQuoteService">
    <port name="StockQuotePort" binding="tns2:StockQuoteBinding">
      <tns3:address xsi:type="tAddress" location="http://localhost/StockQuote/StockQuote.php"/>
    </port>
  </service>
</definitions>

<!-- this line identifies this file as WSDL generated by SCA for PHP. Do not remove -->

add a note add a note

User Contributed Notes 1 note

up
1
deadguysfrom at gmail dot com
14 years ago
In order for SCA to find the service class, the script filename must match the service class name.  In this case, StockQuote.php
To Top