php 调用wcf 服务,.net – 使用PHP客户端的WCF服务 – 复杂类型作为参数不起作用...

我有三种方法的WCF服务.其中两个方法返回自定义类型(这些按预期工作),第三个方法将自定义类型作为参数并返回一个布尔值.通过PHP soap客户端调用第三个方法时,它返回“未设置为对象实例的对象引用”异常.

示例自定义类型:

_

公共类MyClass

Private _propertyA As Double

_

Public Property PropertyA() As Double

Get

Return _propertyA

End Get

Set(ByVal value As Double)

_propertyA = value

End Set

End Property

Private _propertyB As Double

_

Public Property PropertyB() As Double

Get

Return _propertyB

End Get

Set(ByVal value As Double)

_propertyB = value

End Set

End Property

Private _propertyC As Date

_

Public Property PropertyC() As Date

Get

Return _propertyC

End Get

Set(ByVal value As Date)

_propertyC = value

End Set

End Property

结束班

方法:

公共函数Add(ByVal param As MyClass)As Boolean Implements IService1.Add

‘…

结束功能

PHP客户端调用:

$客户端 – >添加(阵列( ‘PARAM’=&GT阵列(

‘PropertyA’=> 1,

‘PropertyB’=> 2,

‘PropertyC’=> “2009-01-01”

)));

WCF服务适用于.Net客户端,但我是PHP的新手,无法使其工作.

是否可以在PHP中创建“MyClass”的实例.

任何帮助,将不胜感激.

注意:我使用的是PHP 5(适用于Windows的XAMPP 1.7.0).

谢谢

马特

解决方法:

我不再需要XAMPP设置才能测试,但这里有一些示例代码:

PHP:

$wsdl = "https://....../ServiceName.svc?wsdl";

$endpoint = "https://...../ServiceName.svc/endpointName";

$client = new SoapClient($wsdl, array('location'=>$endpoint));

$container = new stdClass();

$container->request->PropertyA = 'Test 1';

$container->request->PropertyB = 'Test 2';

$container->request->PropertyC = '05/10/2010';

$response = $client->ServiceMethodA($container);

request是Web服务所需参数的名称.

如果您具有引用其他自定义类型的自定义类型,则可以按如下方式设置这些属性:

$container->request->OtherCustomType->Property1 = 'Test';

希望有所帮助.

标签:php,net,wcf

来源: https://codeday.me/bug/20190730/1585252.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值