合同需要Duplex,但Binding'BasicHttpBinding'不支持它或配置不正确

时间:2014-07-17 18:44:43

标签: c# wcf wcf-binding

我已经发布了类似的问题,并通过建议交叉检查我的解决方案。我仍然遇到上述错误,我根本不知道这里出了什么问题。请帮忙。在我的app.xml中,name和contract都是完全限定名,我使用的是binding = wsDualHttpBinding。

我的app.xml文件如下:

<?xml version="1.0"?>
<configuration>
<startup>
  <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/>
</startup>
<system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior name="ServiceBehavior">
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="true" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <services>
                <service behaviorConfiguration="ServiceBehavior" 
                         name="ABCNotificationEventService.ABCNotificationService">
                        <endpoint address="http://localhost:8799/ABCNotificationService" 
                                  binding="wsDualHttpBinding" 
                                  contract="ABCNotificationEventService.INotifyServiceContract">               
                        </endpoint>
                        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
                </service>
        </services>
    </system.serviceModel>
</configuration>

我的INotifyServiceContract如下:

    namespace ABCNotificationEventService
{
    [ServiceContract]
    public interface INotifyServiceEvents
    {
        [OperationContract(IsOneWay = true)]
        void showErrorNotification();

        [OperationContract(IsOneWay = true)]
        void enableServiceStoppedNotification();
    }

    [ServiceContract(CallbackContract = typeof(INotifyServiceEvents))]
    public interface INotifyServiceContract
    {
        [OperationContract]
        void subscribeEvent();

        [OperationContract]
        void fireErrorNotifyEvent();

        [OperationContract]
        void fireEnableServiceStopNotifyEvent();

    }
}

以上实现的类如下:

    namespace ABCNotificationEventService
{
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    public class ABCNotificationService : INotifyServiceContract
    {
        static Action errorNotifyEvent = delegate { };
        static Action enableServiceStopNotifyEvent = delegate { };

        public void fireErrorNotifyEvent()
        {
            //Issue the event to the subscriber 
            errorNotifyEvent();
        }

        public void fireEnableServiceStopNotifyEvent()
        {
            //Issue the event to the subscriber 
            enableServiceStopNotifyEvent();
        }

        public void subscribeEvent()
        {
            //When subscriber calls for the SubscribeEvent Method of Publisher
            //This method gets executed the and the publisher is able to store the reference to the client instance
            INotifyServiceEvents subscriber = OperationContext.Current.GetCallbackChannel<INotifyServiceEvents>();
            errorNotifyEvent += subscriber.showErrorNotification;
            enableServiceStopNotifyEvent += subscriber.enableServiceStoppedNotification;
        }
    }
}

当我执行以下代码行时出现上述错误:

Uri httpUrl = new Uri("http://localhost:8799/ABCNotificationService/");
            notifyServiceHost = new ABCNotificationEventService.ABCNotificationService();
            notifyService = new ServiceHost(notifyServiceHost, httpUrl);
            notifyService.Open();

0 个答案:

没有答案