WCF - パブリッシャーとサブスクライバー - サブスクリプションの問題
-
19-09-2019 - |
質問
パブリッシャーインターフェース
[ServiceContract]
public interface IPublisherInterface
{
[OperationContract(IsOneWay = false)]
void Publish(MessageClass e, string topicName);
}
加入者インターフェース
[ServiceContract(CallbackContract = typeof(IPublisherInterface))]
public interface ISubscriberInterface
{
[OperationContract]
void Subscribe(string topicName);
[OperationContract]
void UnSubscribe(string topicName);
}
購読者プログラム
class Program
{
static void Main(string[] args)
{
DuplexChannelFactory<ISubscriberInterface> namedPipeFactory =
new DuplexChannelFactory<ISubscriberInterface>(
new InstanceContext(new PublisherService()),
new NetNamedPipeBinding(),
new EndpointAddress("net.pipe://localhost/Sub"));
ISubscriberInterface pipeProxy = namedPipeFactory.CreateChannel();
pipeProxy.Subscribe("name");
//SubscriberForm f = new SubscriberForm(pipeProxy);
//f.ShowDialog();
}
}
このメッセージが表示されるのはなぜですか?
The message with Action 'http://tempuri.org/ISubscriberInterface/Subscribe' cannot be
processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher.
This may be because of either a contract mismatch (mismatched Actions between sender and
receiver) or a binding/security mismatch between the sender and the receiver. Check that
sender and receiver have the same contract and the same binding (including security
requirements, e.g. Message, Transport, None)."
これが私のホストです
class Program
{
static void Main(string[] args)
{
ServiceHost _publisherServiceHost = new ServiceHost(typeof(PublisherService), new Uri[] { new Uri("net.pipe://localhost/") });
_publisherServiceHost.AddServiceEndpoint(
typeof(IPublisherInterface),
new NetNamedPipeBinding(),
"Pub");
_publisherServiceHost.Open();
ServiceHost _subscriberServiceHost = new ServiceHost(typeof(PublisherService), new Uri[] { new Uri("net.pipe://localhost/") });
_subscriberServiceHost.AddServiceEndpoint(
typeof(IPublisherInterface),
new NetNamedPipeBinding(),
"Sub");
_subscriberServiceHost.Open();
Console.WriteLine("Server is Running.");
Console.ReadLine();
}
}
解決
あなたの問題はここにあると思います:
_subscriberServiceHost.AddServiceEndpoint(
typeof(IPublisherInterface),
new NetNamedPipeBinding(),
"Sub");
サブスクライバ サービス ホストは次を使用して作成されます。 IPublisherInterface 契約書、それは間違っています。そのはず ISubscriberInterface その代わり
他のヒント
あなたは第二のホスト開口部を持ちますか?それはすべきではない。
ServiceHost _subscriberServiceHost = new ServiceHost(typeof(SubscriberService), new Uri[] { new Uri("net.pipe://localhost/sub") });
_subscriberServiceHost.AddServiceEndpoint(
typeof(ISubscriberInterface),
new NetNamedPipeBinding(),
"Sub");
_subscriberServiceHost.Open();
私は名前を推測しているが、私はおそらくあなたがあなたのISubscriberInterface実装に名前を与えられたことを推測します。
所属していません StackOverflow