加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 21:34:10 所属栏目:PHP教程 来源:网络整理
导读:我有三种方法的WCF服务.其中两个方法返回自定义类型(这些按预期工作),第三个方法将自定义类型作为参数并返回一个布尔值.通过 PHP soap客户端调用第三个方法时,它返回“未设置为对象实例的对象引用”异常. 示例自定义类型: ?_ 公共类MyClass Private _proper
我有三种方法的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';

希望有所帮助.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读