这是你需要做的。
只是知道,我试图重现你的情况…
>对于本示例,我使用名为Function1的WebMethod创建了.NET示例Web服务,这些是参数:
Function1(Contact Contact, string description, int amount)
>其中Contact只是一个bean类,它有id和name的getters和setters,就像你的case。
>您可以下载此.NET示例web服务:
代码。
这是你需要在PHP端做:
(测试和工作)
/* Create a class for your webservice structure, in this case: Contact */
class Contact {
function Contact($id, $name)
{
$this->id = $id;
$this->name = $name;
}
}
/* Initialize webservice with your WSDL */
$client = new SoapClient("http://localhost:10139/Service1.asmx?wsdl");
/* Fill your Contact Object */
$contact = new Contact(100, "John");
/* Set your parameters for the request */
$params = array(
"Contact" => $contact,
"description" => "Barrel of Oil",
"amount" => 500,
);
/* Invoke webservice method with your parameters, in this case: Function1 */
$response = $client->__soapCall("Function1", array($params));
/* Print webservice response */
var_dump($response);
?>
我怎么知道这是工作?
>如果你做print_r($ params);您将看到此输出,因为您的webservice期望:
Array ( [Contact] => Contact Object ( [id] => 100 [name] => John )
[description] => Barrel of Oil [amount] => 500 )
>当我调试示例.NET webservice时,我得到这个:
(正如你所看到的,Contact对象不是null和其他参数,这意味着你的请求从PHP端成功完成)。
> .NET示例webservice的响应是预期的,并在PHP端显示:
object(stdClass)[3] public ‘Function1Result’ => string ‘Detailed
information of your request! id: 100, name: John, description: Barrel
of Oil, amount: 500’ (length=98)
希望这可以帮助 :-)