0

我有一个测试继承合同和回调合同的测试项目。

更新 1:我用接口植入更新了所有主题

通过阅读这篇文章:http ://codeidol.com/csharp/wcf/Service-Contracts/Contract-Inheritance/#part-16

这是可能的,但是当我尝试时,它失败了。

class Program
    {
        static void Main(string[] args)
        {
            ServiceHost Service_IServer = new ServiceHost(new ServiceImplemantation(), new Uri(@"net.tcp://localhost:8080/"));
            Service_IServer.AddServiceEndpoint(typeof(IService), new NetTcpBinding(), "Service");
            Service_IServer.Open();
            ServiceHost Service_I_IP = new ServiceHost(new IPImplemantation(), new Uri(@"net.tcp://localhost:8080/"));
            Service_I_IP.AddServiceEndpoint(typeof(I_IP), new NetTcpBinding(), "Service");
            Service_I_IP.Open();
            Console.ReadLine();
        }
    }
    [ServiceContract]
    public interface I_IP
    {
        [OperationContract]
        string GetIP();
    }
    [ServiceContract]
    public interface IService : I_IP
    {
        [OperationContract]
        void ImTheServer_Print();
    }
    //
    //
    //
    //
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    public class IPImplemantation : I_IP
    {
        public string GetIP()
        {
            return "1.2.3.4";
        }
    }
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    public class ServiceImplemantation : IPImplemantation, IService
    {
        public void ImTheServer_Print()
        {
            Console.WriteLine("ImTheServer_Print");
        }
    }

错误:

'net.tcp://localhost:8080/Service' 上的 ChannelDispatcher 与合同 '"I_IP"' 无法打开其 IChannelListener。

4

1 回答 1

-1

确保将其装饰为OneWay.

[OperationContract(IsOneWay = true)]
void GetIP();
于 2013-04-19T17:02:42.803 回答