有没有可用的 PHP 工具可用于生成消费代码 网络服务 基于其 WSDL?类似于在 Visual Studio 或 Eclipse 插件中单击“添加 Web 引用”,它对 Java 执行相同的操作。

有帮助吗?

解决方案

我取得了巨大的成功 wsdl2php. 。它将自动为 Web 服务中使用的所有对象和方法创建包装类。

其他提示

在 PHP 5 中你可以使用 肥皂客户端 在 WSDL 上调用 Web 服务功能。 例如:

$client = new SoapClient("some.wsdl");

$client 现在是一个对象,它具有 some.wsdl 中定义的类方法。因此,如果 WSDL 中有一个名为 getTime 的方法,那么您只需调用:

$result = $client->getTime();

其结果(显然)将位于 $result 变量中。您可以使用 __getFunctions 方法返回所有可用方法的列表。

我用过 努肥皂 在过去。我喜欢它,因为它只是一组可以包含的 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 中指定的项目。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top