php怎么调用client,如何使用SoapClient类进行PHP SOAP调用

这是你需要做的。

只是知道,我试图重现你的情况…

>对于本示例,我使用名为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)

希望这可以帮助 :-)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值