【问题标题】:Consume WCF service with dataContract as a parameter from PHP使用带有 dataContract 作为 PHP 参数的 WCF 服务
【发布时间】: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 中发布 节点。
  • 请分享客户端和服务器的配置位。

标签: php wcf soap


【解决方案1】:
$parameter= array("CompositeType"=>$obj); 

在复合中更改 CompositeType(= 与接口中的变量名称完全相同)

【讨论】:

    猜你喜欢
    • 2013-09-10
    • 1970-01-01
    • 1970-01-01
    • 2010-10-04
    • 1970-01-01
    • 2011-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多