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

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了.net – 使用PHP客户端的WCF服务 – 复杂类型作为参数不起作用脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我有三种方法的WCF服务.其中两个方法返回自定义类型(这些按预期工作),第三个方法自定义类型作为参数并返回一个布尔值.通过 PHP SOAp客户端调用第三个方法时,它返回“未设置为对象实例的对象引用”异常.

示例自定义类型:

 _
公共类MyClass

PRivate _proPErtyA As Double
<Datamember()> _
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
<DataMember()> _
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
<DataMember()> _
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’=>阵列(
‘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';

希望有所帮助.

脚本宝典总结

以上是脚本宝典为你收集整理的.net – 使用PHP客户端的WCF服务 – 复杂类型作为参数不起作用全部内容,希望文章能够帮你解决.net – 使用PHP客户端的WCF服务 – 复杂类型作为参数不起作用所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。