我已经使用 ASP.NET(在 C# 中)编写了一个 Web 服务,并且我正在尝试使用 NuSOAP 编写一个示例 PHP 客户端。我被绊倒的地方是如何做到这一点的例子;一些显示soapval
正在使用(而且我不太了解参数 - 例如false
作为string
类型传递等),而另一些只是使用直接array
s。假设我报告的 Web 服务的 WSDLhttp://localhost:3333/Service.asmx?wsdl
如下所示:
POST /Service.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/webservices/DoSomething"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<DoSomething xmlns="http://tempuri.org/webservices">
<anId>int</anId>
<action>string</action>
<parameters>
<Param>
<Value>string</Value>
<Name>string</Name>
</Param>
<Param>
<Value>string</Value>
<Name>string</Name>
</Param>
</parameters>
</DoSomething>
</soap:Body>
</soap:Envelope>
我的第一次 PHP 尝试如下所示:
<?php
require_once('lib/nusoap.php');
$client = new nusoap_client('http://localhost:3333/Service.asmx?wsdl');
$params = array(
'anId' => 3, //new soapval('anId', 'int', 3),
'action' => 'OMNOMNOMNOM',
'parameters' => array(
'firstName' => 'Scott',
'lastName' => 'Smith'
)
);
$result = $client->call('DoSomething', $params, 'http://tempuri.org/webservices/DoSomething', 'http://tempuri.org/webservices/DoSomething');
print_r($result);
?>
现在除了 Param 类型是一种复杂类型,我很确定我的简单$array
尝试不会自动使用,我在我的 Web 服务中设置断点并看到我标记为的方法WebMethod
(不重命名它,它的字面意思DoSomething
)并且看到参数都是默认值(int
is 0
,string
isnull
等)。
我的 PHP 语法应该是什么样的,我必须做什么才能Param
正确传递类型?