【发布时间】:2009-07-21 13:53:53
【问题描述】:
我在服务器上有一堂课
[MessageContract]
public class RemoteFileInfo : IDisposable, INotifyPropertyChanged
{
[MessageHeader(MustUnderstand = true)]
public string _FileName;
[MessageHeader(MustUnderstand = true)]
public string FileName
{
get { return _FileName; }
set { _FileName = value; }
}
[MessageBodyMember(Order = 1)]
public System.IO.Stream _FileByteStream;
[MessageHeader(MustUnderstand = true)]
public System.IO.Stream FileByteStream
{
get { return _FileByteStream; }
set { _FileByteStream = value; }
}
public void Dispose()
{
// close stream when the contract instance is disposed.
// this ensures that stream is closed when file download
// is complete, since download procedure is handled by the client
// and the stream must be closed on server.
if (_FileByteStream!=null)
{
_FileByteStream.Close();
_FileByteStream = null;
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void SendPropertyChanged(String propertyName)
{
if ((this.PropertyChanged != null))
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
}
我通过 WCF 与我的服务器通信。这个类应该是 [MessageContract] 因为流式传输 - (我所有的其他类都使用 [DataContract])。
我的问题是,在客户端使用 SvcUtil 生成类后,我丢失了 INotify... 接口...我明白了:
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.MessageContractAttribute(WrapperName="RemoteFileInfo", WrapperNamespace="http://tempuri.org/", IsWrapped=true)]
public partial class RemoteFileInfo
{
[System.ServiceModel.MessageHeaderAttribute(Namespace="http://tempuri.org/")]
public System.IO.Stream FileByteStream;
[System.ServiceModel.MessageHeaderAttribute(Namespace="http://tempuri.org/")]
public string FileName;
[System.ServiceModel.MessageHeaderAttribute(Namespace="http://tempuri.org/")]
public string _FileName;
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://tempuri.org/", Order=0)]
public System.IO.Stream _FileByteStream;
public RemoteFileInfo()
{
}
public RemoteFileInfo(
System.IO.Stream FileByteStream,
string FileName,
string _FileName,
System.IO.Stream _FileByteStream)
{
this.FileByteStream = FileByteStream;
this.FileName = FileName;
this._FileName = _FileName;
this._FileByteStream = _FileByteStream;
}
}
如果没有 INotifyPropertyChanged,我知道数据绑定不起作用,但我可以像这样在客户端添加它:
public partial class RemoteFileInfo : System.ComponentModel.INotifyPropertyChanged
{
#region INotifyPropertyChanged Members
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
#endregion
}
但数据绑定仍然不起作用。你有什么主意吗? 我根本无法将数据绑定与 [MessageContract] 类一起使用???
提前感谢您的回答!
【问题讨论】:
标签: c# wpf wcf data-binding