2009-01-28 74 views
2

我有一个WCF服务有三种方法。其中两个方法返回自定义类型(按预期工作),第三个方法将自定义类型作为参数并返回一个布尔值。当通过PHP soap客户端调用第三种方法时,它会返回一个'未设置为对象实例的对象引用'异常。WCF服务与PHP客户端 - 复杂类型作为参数不起作用

实施例自定义类型:

_ 公共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 

末级

方法:

公共功能添加(BYVAL PARAM作为MyClass的)作为布尔值实现IService1.Add '... 结束函数

PHP客户端呼叫:

$客户机 - >添加(阵列(' PARAM'=>数组( 'PropertyA'=> 1, 'PropertyB'= > 2, 'PropertyC'=>“2009-01-01” )));

WCF服务对.Net客户端正常工作,但我是PHP新手,无法使其工作。

是否有可能在PHP中创建'MyClass'实例。

任何帮助,将不胜感激。

注意:我正在使用PHP 5(适用于Windows的XAMPP 1.7.0)。

感谢

马特

+0

你试过$ myClassInstance = new $ Client-> MyClass(); – 2009-01-28 17:24:53

回答

2

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

请求是由Web服务预期的参数的名称。

如果你有到其他自定义类型引用自定义类型,你可以如下设置这些属性:

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

希望有所帮助。

1

我愿意打赌这是因为您使用的是Date类型作为参数之一,它不是通过PHP正确序列化。尝试使用一个字符串并手动解析它。我知道,不是很安全,但你能做什么?

1

我已经尝试将MyClass中的所有属性类型更改为String,但仍然得到相同的错误。我也尝试使用$ myClassInstance = new $ Client-> MyClass()来实例化MyClass;我试图使用$ myClassInstance = new $ Client-> MyClass()来实例化MyClass。但是这产生以下错误:

“类名称必须是一个有效的对象或在filename.php一个字符串”

高于例如所需要的服务的命名空间$ myClassInstance = new $ Client-> Namespace \ MyClass()?

该服务的wsdl不包含MyClass的任何描述。在MyClass类有DataContract()ServiceKnownType(的GetType(MyClass的))属性和属性都有数据成员()属性应用,但仍然没有提及的MyClass在WSDL。这可能是PHP无法实例化它的原因吗?

感谢

马特

1

本准则

$ myClassInstance =新的$客户 - > MyClass的();语法错误

但是这个代码

$ myClassInstance =新的$客户 - > MyClass的;而此代码

这是正确的语法 去除双括号

1

WCF中WSDL是一个巨大的不同比较旧的Web服务,它拆分成XSD不同的文件。请仔细的你WSDL阅读,你应该能够看到几行这样

这里是你的XSD。

相关问题