ChannelFactory has no endpoint address, why?

When I create a new instance of ChannelFactory:

var factory = new ChannelFactory<IMyService>();

and that I am creating a new channel, I have an exception saying that the endpoint address is NULL.

My configuration inside my web.config is indicated as indicated, and everything is as it should be (especially the endpoint address).

If I create a new MyServiceClientBase, it loads the entire configuration from my factory channel:

var factoryWithClientBase = new MyServiceClientBase().ChannelFactory;
Console.WriteLine(factoryWithClientBase.Endpoint.Address); //output the configuration inside the web.config


var factoryWithChannelFactory = new ChannelFactory<IMyService>();
Console.WriteLine(factoryWithChannelFactory.Endpoint.Address); //output nothing (null)

Why?

+3
source share
3 answers

I finally found the answer. ChannelFactory does not read information from your Web.Config / app.config. ClientBase (which then works with ChannelFactory).

All this cost me several hours of work, but I finally found the right reason.

:)

+5

, Web.Config:

<endpoint address="http://localhost:2000/MyService/" binding="wsHttpBinding"
    behaviorConfiguration="wsHttpBehaviour" contract="IService"
    name="MyWsHttpEndpoint" />

ChannelFactory :

var factory = new ChannelFactory<IMyService>("MyWsHttpEndpoint");
+9

ChannelFactory, , web.config. AnAngel . , . , ( )

, web.config VS, ServiceReference ( Service Reference), , . ( )

<endpoint address="http://localhost:2000/MyService/" binding="wsHttpBinding"
behaviorConfiguration="wsHttpBehaviour" contract="TheCorrectNamespace.IService"
name="MyWsHttpEndpoint" />

The responder did not publish its web.config, so I assume that you most likely made a mistake (by specifying the wrong contract for the endpoints)

+3
source

Source: https://habr.com/ru/post/1699686/


All Articles