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)