代码贴下来了,请高人看看怎么回事,困扰很长时间了服务
using System.ServiceModel;namespace DualWCF.Service
{
    [ServiceContract(CallbackContract = typeof (IMasterSlaverCallback), SessionMode = SessionMode.Required)]
    public interface IMasterSlaverService
    {
        [OperationContract(IsOneWay = true)]
        void Register();
    }    public interface IMasterSlaverCallback
    {
        [OperationContract(IsOneWay = false)]
        string GetSomething();        [OperationContract(IsOneWay = true)]
        void PostSomething();
    }
}实现
using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Activation;namespace DualWCF.Service
{
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single,ConcurrencyMode = ConcurrencyMode.Multiple)]
    [AspNetCompatibilityRequirements(RequirementsMode = System.ServiceModel.Activation.AspNetCompatibilityRequirementsMode.Allowed)]
    [CallbackBehavior(UseSynchronizationContext = false)]
    public class MasterSlaverService : IMasterSlaverService
    {
        public void Register()
        {
            var client=OperationContext.Current.GetCallbackChannel<IMasterSlaverCallback>();
            client.PostSomething();
            client.GetSomething();
        }
    }
}
客户端
using Client.MasterSlaverService;namespace Client
{
    public class ImpMasterSlaverCallback:IMasterSlaverServiceCallback
    {        public string GetSomething()
        {
            return "something";
        }        public void PostSomething()
        {
            var n = "something";
        }
    }
}客户端调用var client=new MasterSlaverServiceClient(new InstanceContext(new ImpMasterSlaverCallback()));
            client.Register();服务器配置文件
 <system.serviceModel>
    
    <services>
      <service name="DualWCF.Service.MasterSlaverService">
        <endpoint address="" binding="wsDualHttpBinding" contract="DualWCF.Service.IMasterSlaverService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    
  </system.serviceModel>客户端配置
  <system.serviceModel>
    <bindings>
      <wsDualHttpBinding>
        <binding name="WSDualHttpBinding_IMasterSlaverService" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
          maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
          textEncoding="utf-8" useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00" />
          <security mode="Message">
            <message clientCredentialType="Windows" negotiateServiceCredential="true"
              algorithmSuite="Default" />
          </security>
        </binding>
      </wsDualHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://127.1.1.1:8000/service/MasterSlaverService.svc"
        binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_IMasterSlaverService"
        contract="MasterSlaverService.IMasterSlaverService" name="WSDualHttpBinding_IMasterSlaverService">
        <identity>
          <servicePrincipalName value="host/myname" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>

解决方案 »

  1.   

    MasterSlaverServiceClient 双工不能用直接生成的,必须用DuplexChannelFactory
      

  2.   

    楼上的兄弟,能否详细一些,或者给段示例代码
    我是这么写的
    using (var channel = new DuplexChannelFactory<IMasterSlaverServiceChannel>(new InstanceContext(new ImpMasterSlaverCallback()), "WSDualHttpBinding_IMasterSlaverService"))
                {
                    using (var n = channel.CreateChannel())
                    {
                        n.Register();
                    }
                }
    这样还是需要引入服务才能用是吧