PHP5 和 SOAP/WSDL?

发布于 2024-08-27 06:20:25 字数 122 浏览 8 评论 0原文

我现在有一个大问题,我需要创建自己的网络服务,但我真的不知道如何做,有人可以帮助我吗?

也许链接到制作 WSDL/SOAP 代码的简单方法?我已经尝试过 NuSoap,但我无法获得此代码的最终结果,请帮助我。 :)

I have a big problem right now, i need to create my own webservices but i really don't know how, can sombody help me?

maybe link to easy way to make WSDL/SOAP code? i have try NuSoap but i can't get final whit this code, please help me. :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三生池水覆流年 2024-09-03 06:20:25

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 扩展。祝你好运!

A very basic example of a SOAP webservice:

The server part (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();

The client part (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");

And finally the WSDL file (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>

This example assumes you put these three files in a directory that is accessible from http://localhost/test and if you use another location, find and replace with the correct URL.

Also it requires the SOAP PHP extension to be installed. Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文