【发布时间】:2012-01-12 03:01:21
【问题描述】:
我试图从 PHP 客户端使用 WCF 服务但没有成功。 我无法使用将“DataContract”对象作为参数的服务方法。 这是我的代码:
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
}
以下是“CompositeType”合约:
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";
[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
下面是我创建的 PHP 客户端
$obj = new stdClass();
$obj->BoolValue = true;
$obj->StringValue ="Sandeep";
$parameter= array("CompositeType"=>$obj);
echo "\n";
$client = new SoapClient('http://localhost:2051/Service1.svc?wsdl');
$obj1 = $client->GetDataUsingDataContract($parameter);
print_r($obj1);
当我使用上述内容时,DataContarct 作为 Null 传递给 WCF。
解决办法是什么?
【问题讨论】:
-
您使用的是哪个版本的 .Net? .net 3.5 还是 4.0?您能否从您的 asp.net web.config 中发布
节点。 -
请分享客户端和服务器的配置位。