简体   繁体   中英

load wcf hosted on console app with app.config?

Hello im making wcf hosted in console app is possible to load this service with app.config?

ChannelFactory<IService> service = new ChannelFactory<IService>();
service.Endpoint.Behaviors.Add(new WebHttpBehavior());
IService channel = service.CreateChannel();
Console.Read();

This is start of my wcf into console app but how to load wcf config?

Im new in wcf so please be polite for me.

--edit---

So i get errorr s zero application (non-infrastructure) endpoints. This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element.

            ServiceHost serviceHost = null;
            serviceHost = new ServiceHost(typeof(Contracs.Service));
            serviceHost.Open();

and my app.config is

            <?xml version="1.0" encoding="utf-8"?>
            <configuration>
              <system.serviceModel>
<behaviors>
  <endpointBehaviors>
    <behavior name="restfulBehavior">
      <webHttp />
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<services>
  <service name="Contracs.Service">
    <endpoint address="" behaviorConfiguration="restfulBehavior"
      binding="webHttpBinding" bindingConfiguration="" contract="Contracs.IService" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost/Service" />
      </baseAddresses>
    </host>
  </service>
</services>

<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

WCF will by default try to load from the app config.

Here is some more info:

http://msdn.microsoft.com/en-us/library/ms733932(v=vs.110).aspx

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