簡體   English   中英

PHP5和SOAP / WSDL?

[英]PHP5 and SOAP/WSDL?

我現在有一個大問題,我需要創建自己的Web服務,但是我真的不知道如何,有人可以幫我嗎?

也許鏈接到制作WSDL / SOAP代碼的簡單方法? 我已經嘗試過NuSoap,但是我無法最終獲得此代碼,請幫助我。 :)

SOAP Web服務的一個非常基本的示例:

服務器部分( server.php ):

<?php
function getRot13($pInput) {
    $rot = str_rot13($pInput);
    return($rot);
}

function getMirror($pInput) {
    $mirror = strrev($pInput);
    return $mirror;
}

ini_set("soap.wsdl_cache_enabled", "0");

$server = new SoapServer('scramble.wsdl');

$server->addFunction("getRot13");
$server->addFunction("getMirror");

$server->handle();

客戶端部分( client.php ):

<?php
// turn off the WSDL cache
ini_set("soap.wsdl_cache_enabled", "0");

$client = new SoapClient("http://localhost/test/scramble.wsdl");

$origtext = "mississipi";

print("The original text : $origtext\n");

$mirror = $client->getMirror($origtext);
print("The mirrored text : $mirror\n");

$scramble = $client->getRot13($mirror);
print("The scrambled text : $scramble\n");

最后是WSDL文件( scramble.wsdl ):

<?xml version ='1.0' encoding ='UTF-8' ?>
<definitions name='Scramble' 
  targetNamespace='http://localhost/test/scramble.wdsl' 
  xmlns:tns='http://localhost/test/scramble.wdsl' 
  xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/' 
  xmlns='http://schemas.xmlsoap.org/wsdl/'> 

<message name='getRot13Request'> 
  <part name='symbol' type='xsd:string'/> 
</message> 
<message name='getRot13Response'> 
  <part name='Result' type='xsd:string'/> 
</message> 
<message name='getMirrorRequest'> 
  <part name='symbol' type='xsd:string'/> 
</message> 
<message name='getMirrorResponse'> 
  <part name='Result' type='xsd:string'/> 
</message> 

<portType name='ScramblePortType'> 
  <operation name='getRot13'>
    <input message='tns:getRot13Request'/> 
    <output message='tns:getRot13Response'/>   
  </operation>
  <operation name='getMirror'>
    <input message='tns:getMirrorRequest'/> 
    <output message='tns:getMirrorResponse'/>   
  </operation>    
</portType> 

<binding name='ScrambleBinding' type='tns:ScramblePortType'> 
  <soap:binding style='rpc' 
    transport='http://schemas.xmlsoap.org/soap/http'/> 
  <operation name='getRot13'> 
    <soap:operation soapAction='urn:localhost-scramble#getRot13'/> 
    <input> 
      <soap:body use='encoded' namespace='urn:localhost-scramble' 
        encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> 
    </input> 
    <output> 
      <soap:body use='encoded' namespace='urn:localhost-scramble' 
        encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> 
    </output> 
  </operation>
  <operation name='getMirror'> 
    <soap:operation soapAction='urn:localhost-scramble#getMirror'/> 
    <input> 
      <soap:body use='encoded' namespace='urn:localhost-scramble' 
        encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> 
    </input> 
    <output> 
      <soap:body use='encoded' namespace='urn:localhost-scramble' 
        encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> 
    </output> 
  </operation>       
</binding> 

<service name='ScrambleService'> 
  <port name='ScramblePort' binding='ScrambleBinding'> 
    <soap:address location='http://localhost/test/server.php'/> 
  </port> 
</service>
</definitions>

本示例假定您將這三個文件放在可從http:// localhost / test訪問的目錄中,並且如果使用其他位置,請查找並替換為正確的URL。

另外,它需要安裝SOAP PHP擴展。 祝好運!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM