如何通过PHP调用C#Web服务?

cfe*_*uke 3 php c# web-services nusoap

我使用ASP.NET编写了一个Web服务(在C#中),我正在尝试使用NuSOAP编写一个示例PHP客户端.我绊倒的地方是如何做到这一点的例子; 一些显示soapval正在使用(我不太了解参数-比如通过falsestring类型等),而另一些则只是采用了直板array秒.假设我所报告的Web服务的WSDL http://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>
Run Code Online (Sandbox Code Playgroud)

我的第一次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);
?>
Run Code Online (Sandbox Code Playgroud)

现在除了Param类型是一个复杂的类型,我很确定我的简单$array尝试不会自动使用,我正在我的Web服务中查找并看到我标记为的方法WebMethod(没有重命名,它的字面意思DoSomething)并且看到参数都是默认值(intis 0,stringis null等).

我的PHP语法应该是什么样的,以及如何Param正确传递类型?

duc*_*rth 6

你必须包装大量的嵌套数组.

<?php
require_once('lib/nusoap.php');
$client = new nusoap_client('http://localhost:3333/Service.asmx?wsdl');

$params = array(
      'anId' => 3,
      'action' => 'OMNOMNOMNOM',
      'parameters' => array(
              'Param' => array(
                  array('Name' => 'firstName', 'Value' => 'Scott'),
                  array('Name' => 'lastName', 'Value' => 'Smith')
                       )
      )
);
$result = $client->call('DoSomething', array($params), 
                'http://tempuri.org/webservices/DoSomething', 
                'http://tempuri.org/webservices/DoSomething');
print_r($result);
?>
Run Code Online (Sandbox Code Playgroud)