WCF和[DATACONTRACT] + [DATAMEMBER]
|
我想知道如何将DataContract添加到我的服务中?我的意思是,我知道我必须创建一个类,在其顶部放置[DATACONTRACT],然后在每个成员顶部添加[DATAMEMBER],然后如何将DataContract添加到服务中(我已经有一个[ServiceContract]和在服务上运行的[OperationContract])?
我目前正在以编程方式进行所有操作(没有.config文件)。
一些代码显示了我如何启动和添加OperationContract :(我使用的是.NET 4.0)
服务端:
using (ServiceHost host = new ServiceHost(typeof(StringReverser), new Uri[]{ new Uri(\"net.tcp://localhost\") }))
{
host.AddServiceEndpoint(typeof(IStringReverser), new NetTcpBinding(), \"TCPReverse\");
host.Open();
}
客户端:
Callbacks myCallbacks = new Callbacks();
DuplexChannelFactory<IStringReverser> TCPFactory =
new DuplexChannelFactory<IStringReverser>(
myCallbacks,
new NetTcpBinding());
TCPFactory.Credentials.Windows.ClientCredential = new System.Net.NetworkCredential(\"username\", \"password\");
IStringReverser TCPProxy = TCPFactory.CreateChannel();
Console.WriteLine(\"Client connected\");
提前致谢
没有找到相关结果
已邀请:
2 个回复
断跑胺弄萎
辅奈