【发布时间】:2017-09-20 16:29:38
【问题描述】:
我正在学习 WCF,作为学习的一部分,我发现合同的命名空间应该匹配。我编写了一个合同类(客户端和主机都有自己的副本)并使它们的命名空间不匹配,但我的代码仍然有效。我已经为我的合同和主机类以及客户如何调用合同提供了代码。有人可以告诉我哪里错了吗?
客户端合同类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
namespace GeoLib.Client.Contracts
{
[ServiceContract]
public interface IMessageContract
{
[OperationContract (Name = "ShowMessage")]
void ShowMsg(string message);
}
}
主机合约类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
namespace GeoLib.WindowsHost.Contracts
{
[ServiceContract]
public interface IMessageContract
{
[OperationContract]
void ShowMessage(string message);
}
}
在客户端调用代码:
private void btnMakeCall_Click(object sender, RoutedEventArgs e)
{
ChannelFactory<IMessageContract> factory = new ChannelFactory<IMessageContract>("");
IMessageContract proxy = factory.CreateChannel();
proxy.ShowMsg(txtMessage.Text);
factory.Close();
}
【问题讨论】:
标签: c# wcf namespaces