【发布时间】:2008-11-10 21:19:13
【问题描述】:
我已经使用 ASP.NET(在 C# 中)编写了一个 Web 服务,并且我正在尝试使用 NuSOAP 编写一个示例 PHP 客户端。我被绊倒的地方是如何做到这一点的例子;有些显示正在使用soapval(我不太了解参数 - 例如将false 传递为string 类型等),而另一些则直接使用arrays。假设http://localhost:3333/Service.asmx?wsdl 报告的我的 Web 服务的 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 服务中设置断点并看到我标记为 @987654329 的方法@(不重命名,字面意思是DoSomething)并且看到参数都是默认值(int 是0,string 是null,等等)。
我的 PHP 语法应该是什么样的,我必须做什么才能正确传递 Param 类型?
【问题讨论】:
标签: c# php web-services nusoap