WCF: Why does passing in a remote endpoint fail?

本小妞迷上赌 提交于 2019-12-08 06:03:53

问题


The problem I am having connecting a wcf client application to a host running on a separate machine is documented in a question previously asked:

WCF: Why does passing in a remote endpoint fail?

However, the solution provided here says you need to use a SpnEndpointIdentity with an empty string. Since my code doesn't look anything like the case in the example I have referenced, I need to know what to do with the SpnEndpointIdentity object I have created.

I have a ChannelFactory upon which I call Create channel, passing in an EndpointAddress:

    public override void InitialiseChannel()
    {
        SpnEndpointIdentity spnEndpointIdentity = new SpnEndpointIdentity("");
        var address = new EndpointAddress(EndpointName);

        Proxy = ChannelFactory.CreateChannel(address);
    }

(NB: ChannelFactory is of type IChannelFactory, where T is the service contract interface) So what do I do with spnEndpointIdentity? I can't pass it to CreateChannel.

Or perhaps I can use it somehow when I create the channel factory:

    private ChannelFactory<T> CreateChannelFactory()
    {
        var binding = new NetTcpBinding
        {
            ReaderQuotas = { MaxArrayLength = 2147483647 },
            MaxReceivedMessageSize = 2147483647
        };

        SpnEndpointIdentity spnEndpointIdentity = new SpnEndpointIdentity(""); 
        var channelFactory = new ChannelFactory<T>(binding);

        return channelFactory;
    }

Again, I can't pass it into the constructor, so what do I do with it?

Thanks.


回答1:


You almiost got it.

What you're missing is that you associate the EndpointIdentity with the EndpointAddress, and then provide that to CreateChannel():

SpnEndpointIdentity spnEndpointIdentity = new SpnEndpointIdentity("");
var address = new EndpointAddress(EndpointName, spnEndpointIdentity);


来源:https://stackoverflow.com/questions/1914699/wcf-why-does-passing-in-a-remote-endpoint-fail

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!