我在服务器上有一个班级
[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]类的数据绑定???
提前感谢您的回答!
答案 0 :(得分:0)
消息合约仅指定消息的结构。服务器端的任何接口都不会出现在客户端,因为它们与消息的结构无关。
此外,如果您的客户端是用Java编写的,它对这些接口有什么作用?