簡體   English   中英

使用app.config加載控制台應用程序上托管的wcf?

[英]load wcf hosted on console app with app.config?

您好,我可以將WCF托管在控制台應用中,是否可以通過app.config加載此服務?

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

這是我的WCF進入控制台應用程序的開始,但是如何加載WCF配置?

我是wcf的新手,所以請對我禮貌些。

- 編輯 - -

因此,我得到了errorr的零應用程序(非基礎結構)端點。 這可能是因為沒有為您的應用程序找到配置文件,或者是因為在配置文件中找不到與服務名稱匹配的服務元素,或者因為在服務元素中未定義端點。

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

而我的app.config是

            <?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默認情況下將嘗試從應用程序配置加載。

這是更多信息:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM