douhu7807
douhu7807
2019-03-25 12:41

如何在PHP中使用SOAP WebService的WSDL创建对象?

I am trying to call a Webservice with PHP. It works fine, but I got one function, which throws an NullReferenceException. The function parameters are classes of the Webservice and defined in the WSDL file. In C# I can create instances of these classes, then I can pass these with the method. This works like expected, but in PHP I can't create these instances of the class like in C#.

I tried to create an instance of the class form the WSDL:

$myinstance1 = new SoapVar($content, SOAP_ENC_OBJECT, "Class1Name", $url_WSDL);
$myinstance2 = new SoapVar($content, SOAP_ENC_OBJECT, "Class2Name", $url_WSDL);

and then i tried to call the method with these parameters:

$result = $soapclient->GetMyObjects($myinstance1, $myinstance2);

I guess one problem is, that one of the classes is of type enumeration. The other class is a type of integer array. When I try to call my functions with these parameters I still recieve the NullReferenceException error.

I think the problem is because of the enum type, which isn't converted correctly. Did I instanciate correctly? Does anyone have an idea, how to fix this problem?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • douzhicai7148 douzhicai7148 2年前

    I solved it by generating php classes from the WSDL file. For this I used the tool wsdl2phpgenerator.
    After I passed the values ​​as class objects, it worked.

    点赞 评论 复制链接分享

为你推荐