问题
I have a Duplex service (Singleton), which used to work with WSDualHttpBinding, and after changing it to duplex CustomBinding to support BinaryEncoding for performance reasons, it stopped working. The problem traces to GetCallBackChannel always returns with same HashCode (within that service instance) for all the client requests and the List thinks it already exists in the subscribed channels and wont add to the Subscribers list. I am using C# 3.5
Please suggest a solution..
Thanks in Advance...
public void Subscribe(string topicName)
{
try
{
Notifier.IPublishing subscriber = OperationContext.Current.GetCallbackChannel<IPublishing>();
Notifications.Filter.AddSubscriber(topicName, subscriber);
}
catch (Exception ex)
{
ErrorLog.WriteToLog("Subscribe\n" + ex.ToString());
}
}
static public void AddSubscriber(String topicName, IPublishing subscriberCallbackReference)
{
lock (typeof(Filter))
{
if (SubscribersList.ContainsKey(topicName))
{
if (!SubscribersList[topicName].Contains(subscriberCallbackReference))
{
SubscribersList[topicName].Add(subscriberCallbackReference);
}
}
else
{
List<IPublishing> newSubscribersList = new List<IPublishing>();
newSubscribersList.Add(subscriberCallbackReference);
SubscribersList.Add(topicName, newSubscribersList);
}
}
}
回答1:
Looks like this is an Undocumented Issue with .Net 3.5. Tried the same thing in .Net 4.0 it works like a charm.
My objective was to use Binary Encoding with wsDualHTTPBinding, due to the reason that Windows Server 2008/IIS7 was not an option at that time this issue was raised.
The preferred solution to use binary encoding with duplex binding is to use nettcpbinding, and it has a dependency that that IIS7 (unless you are self hosting) is required which is only available on windows server 2008 or later.
We convinced the our infrastructure group to upgrade.. and all is good now :)
来源:https://stackoverflow.com/questions/3839311/wcf-custombinding-duplex-binaryencoding-no-security-cannot-call-back