2016-11-18 7 views
1

代わりに文字列の内容をURLとして引数を取るPHP SoapClientコンストラクターを呼び出すことは可能ですか?私の例ではURLの代わりに変数からWSDLを使用してSoapClientコンストラクターを呼び出す

は、私が)(saveXMLと文字列に書きます操作のDOMDocument含むWSDLを持っています。

アイデアは、可能な場合は、ファイルシステムに手を触れないことです。私はphp://メモリを試していますが、stream_contentのような関数でストリームコンテンツを取得する際のテストは、ストリームコンテキストが消滅したと思われるので空の文字列になります。別の方法がありますか?

答えて

1

はい、ファイルシステムに触れることなく、あなたのWSDL文字列、すべてのを含む変数とSoapClientクラスをインスタンス化することが可能です。 SoapClientは、URIパラメータを必要とするので、私たちはData URIを作成し、それを渡します:

$wsdlstring = <<<WSDL 
<?xml version="1.0" encoding="utf-8"?> 
<definitions name="SoapArrayTest" 
        xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
        xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 
        xmlns:tns="http://test-uri/" 
        xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
        xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
        xmlns="http://schemas.xmlsoap.org/wsdl/" 
        targetNamespace="http://test-uri/" 
    > 
    <types> 
    <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://test-uri/"> 
     <complexType name="Baz"> 
     <sequence> 
      <element name="fruit" type="tns:StringArray"/> 
      <element name="vegetables" type="tns:StringArray"/> 
     </sequence> 
     </complexType> 
     <element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="BazElement" type="tns:Baz"/> 
     <complexType name="StringArray"> 
     <sequence> 
      <element name="item" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/> 
     </sequence> 
     </complexType> 
     <element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="StringArrayElement" type="tns:StringArray"/> 
    </schema> 
    </types> 
    <message name="fooRequest"> 
    </message> 
    <message name="fooResponse"> 
    <part name="result" type="tns:Baz"/> 
    </message> 
    <portType name="TestPortType"> 
    <operation name="foo"> 
     <input message="tns:fooRequest"/> 
     <output message="tns:fooResponse"/> 
    </operation> 
    </portType> 
    <binding name="TestBinding" type="tns:TestPortType"> 
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> 
    <operation name="foo"> 
     <soap:operation soapAction="#foo" style="rpc"/> 
     <input /> 
     <output > 
     <soap:body parts="result" use="literal" namespace="http://test-uri/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> 
     </output> 
    </operation> 
    </binding> 
    <service name="TestService"> 
    <port name="TestPort" binding="tns:TestBinding"> 
     <soap:address location="http://example.com"/> 
    </port> 
    </service> 
</definitions> 
WSDL; 

$doc = new DOMDocument(); 
$doc->loadXML($wsdlstring); 
$data = $doc->saveXML(); 
$wsdl = 'data://text/plain;base64,'.base64_encode($data); 
$soapclient = new SoapClient($wsdl); 
var_dump($soapclient->__getFunctions()); 
+0

これはただのSoapClientインスタンスを作成する際にエラーが発生しているようだ:「URLで無コンマ:RFC2397ストリームをオープンに失敗しました」 – Russ

+0

私は実際のサンプルを提供するために答えを広げましたが、技術的にはWSDLはPHPファイル自体のファイルシステムに存在します。 WSDLは、ちょうど 'DOMDocument'メソッド呼び出しで構成されている場合しかし、それはメモリ内に完全に常駐します。私は余裕を持ってすぐに答えを更新するので、WSDLはDOMDocumentを使ってオンザフライで構築されます。 –

+0

私はここで鍵と思っていると思います。はい、 'SoapClient'はURLを引数として取ることができますが、PHPがストリームコンテキストのように処理するので、質問のように文字列の内容を渡すことができます。だから我々は、データ 'に置き換えることができます:// 'ではなく'ファイル:// 'や'ます。http:// ' –

関連する問題