如何轻松使用 PHP 的 Web 服务
-
08-06-2019 - |
解决方案
我取得了巨大的成功 wsdl2php. 。它将自动为 Web 服务中使用的所有对象和方法创建包装类。
其他提示
我用过 努肥皂 在过去。我喜欢它,因为它只是一组可以包含的 PHP 文件。Web 服务器上无需安装任何内容,也无需更改配置选项。它还具有 WSDL 支持,这是一个额外的好处。
这 文章 解释如何使用 PHP SoapClient 调用 api Web 服务。
那么,这些功能特定于您用于以这些语言进行开发的工具。
如果(例如)您使用记事本编写代码,您将不会拥有这些工具。因此,也许您应该询问您正在使用的工具的问题。
对于 PHP: http://webservices.xml.com/pub/a/ws/2004/03/24/phpws.html
嗨,我从这个网站得到这个: http://forums.asp.net/t/887892.aspx?Consume+an+ASP+NET+Web+Service+with+PHP
Web服务有方法 Add
它需要两个参数:
<?php
$client = new SoapClient("http://localhost/csharp/web_service.asmx?wsdl");
print_r( $client->Add(array("a" => "5", "b" =>"2")));
?>
假设您获得了以下信息:
<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:int="http://thesite.com/">
<x:Header/>
<x:Body>
<int:authenticateLogin>
<int:LoginId>12345</int:LoginId>
</int:authenticateLogin>
</x:Body>
</x:Envelope>
和
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<authenticateLoginResponse xmlns="http://thesite.com/">
<authenticateLoginResult>
<RequestStatus>true</RequestStatus>
<UserName>003p0000006XKX3AAO</UserName>
<BearerToken>Abcdef1234567890</BearerToken>
</authenticateLoginResult>
</authenticateLoginResponse>
</s:Body>
</s:Envelope>
假设访问 http://thesite.com/ 说WSDL地址是:http://thesite.com/PortalIntegratorService.svc?wsdl
$client = new SoapClient('http://thesite.com/PortalIntegratorService.svc?wsdl');
$result = $client->authenticateLogin(array('LoginId' => 12345));
if (!empty($result->authenticateLoginResult->RequestStatus)
&& !empty($result->authenticateLoginResult->UserName)) {
echo 'The username is: '.$result->authenticateLoginResult->UserName;
}
正如您所看到的,尽管 LoginId 值可以更改,但 PHP 代码中使用了 XML 中指定的项目。
不隶属于 StackOverflow