我有三种方法的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’=>阵列(
‘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