小编Gho*_*eza的帖子

为什么在WCF中使用LocalChannel时执行序列化?

Microsoft提供了一个名为LocalChannel的WCF示例,用于说明如何在同一ApplicationDomain中调用服务时实现自定义绑定以绕过不必要的开销.它的样本描述表明:

这对于客户端和服务在同一应用程序域中运行并且必须避免典型WCF通道堆栈(消息的序列化和反序列化)的开销的情况非常有用.

我在我的项目中使用了这个代码,但是尽管声称在调用服务时似乎发生了序列化.

为了更清楚,我已将代码更改为以下内容以使用数据协定,因此可以轻松确定是否正在执行序列化.

# region Service Contract

[ServiceContract]
public interface IGetPrice
{
    [OperationContract]
    ProductDTO GetPriceForProduct(int productCode);
}


[DataContract]
public class ProductDTO
{
    private string _price;

    public ProductDTO(string price)
    {
        _price = price;
    }

    #region Overrides of Object

    public override string ToString()
    {
        return string.Format("Price = '{0}'", _price);
    }

    #endregion

    [DataMember]
    public string Price
    {
        get { return _price; }
        set { _price = value; }
    }
}

public class GetPrice : IGetPrice
{
    #region IGetPrice Members

    public …
Run Code Online (Sandbox Code Playgroud)

.net c# wcf wcf-binding

5
推荐指数
1
解决办法
229
查看次数

标签 统计

.net ×1

c# ×1

wcf ×1

wcf-binding ×1