代码之家  ›  专栏  ›  技术社区  ›  Matt F

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

  •  3
  • Matt F  · 技术社区  · 16 年前

    自定义类型示例:

    _ 公共类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参数作为MyClass)作为布尔值实现IService1.Add ' ... 端函数

    PHP客户端调用:

    $client->添加(数组('param'=>数组)( “PropertyA'=>1. “PropertyC”=>"2009-01-01" )));

    任何帮助都将不胜感激。

    注意:我使用的是PHP5(适用于Windows的XAMPP1.7.0)。

    马特

    5 回复  |  直到 16 年前
        1
  •  3
  •   Matt F    14 年前

    我不再使用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);
    

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

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

    希望有帮助。

        2
  •  1
  •   Randolpho    16 年前

        3
  •  1
  •   Matt F    16 年前

    我曾尝试将MyClass中的所有属性类型更改为String,但仍然出现相同的错误。

    “类名必须是filename.php中的有效对象或字符串”

    数据合同() ServiceKnownType(GetType(MyClass)) 属性和属性都具有 数据成员()

    谢谢

    马特

        4
  •  1
  •   Paul Evangel Tapon    15 年前

    此代码

    $myClassInstance=新的$Client->MyClass();是一个语法错误

    但是这个代码

    $myClassInstance=新的$Client->MyClass;当这个代码工作时

    去掉双括号

        5
  •  1
  •   Vincent    14 年前

    这是你的xsd。