简体   繁体   中英

Calling service from self host

I have a very complex scenario in which my services are dynamically loaded and everything is done programmatically. In particular I have a service that has 2 endpoints

net.pip://localhost/test net.pipe://localhost/test/mex

I have a client that access this without issue as well as the WCF Test Client tool.

I am trying to access the service from the selfhost wrapper. I have read you just treat it as a client and create a factory and channel but something is preventing this from working. The same code that works on the client will not work in the wrapper. The code just

    private IAgentBase GetLocalClient(string serviceEndpointName)
    {
        var factory = new ChannelFactory<IAgentBase>(serviceEndpointName);
        return factory.CreateChannel();
    }

This does return a proxy and then I call a method on the service...

    var proxy = GetLocalClient("net.pipe://localhost/test");
    proxy.DoThis();

But the code just goes someplace - keeps running and no error. The statement never completes. When I step over that line or set a BP or a try catch, it never completes the method call

Change your GetLocalClient to the following

 public IAgentBase GetlocalClient(string ed)
    {
         EndpointAddress edi = new EndpointAddress(ed);
        var channel = ChannelFactory<IAgentBase>.CreateChannel(new NetNamedPipeBinding(), edi);
        return channel;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM