はじめに
いまさらながら、WCFを使えないかと10 行でズバリ!! サービスの起動の自動化 (WCF の IIS ホスティング) (C#)を試していたがうまく動作しない。
Viausl Studio 2015を使い構築したが、どうにか動作できるようになったので記載する。
簡単にWCFを使えるようになっていた。
Visual Studio 2010との違い
Web.config
10行でズバリでは、WCF サービス構成エディタを使って設定をおこなった。
Visual Studio 2015では、Wcf Service アプリケーションを作成すると、下記のようようになっており、サービスの指定がない。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.6"/>
<httpRuntime targetFramework="4.6"/>
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
</httpModules>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- メタデータ情報の開示を避けるには、展開する前に下の値を false に設定します -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- デバッグ目的で障害発生時の例外の詳細を受け取るには、下の値を true に設定します。例外情報の開示を避けるには、展開する前に false に設定します -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="ApplicationInsightsWebTracking"/>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"
preCondition="managedHandler"/>
</modules>
<!--
デバッグ中に Web アプリケーションのルートを直接参照するには、下の値を true に設定します。
Web アプリケーション フォルダーの情報開示を避けるには、展開する前に false に設定します。
-->
<directoryBrowse enabled="true"/>
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>
</configuration>
Visual Studio 2015では、個々のサービスの指定は不要で、サービスを追加しても、web.configの修正は必要がないようだ。
Service の追加
Service1を指定通り変更してもService1がそのまま有効になっていた。
WCF サービスを追加でService2.svcを登録して、関係のないファイルがいくつかできるが、下記のファイルを削除した。
- Service2.svc.cs
- IService2.cs
Service2.svcには、下記のように指定した。
<%@ ServiceHost Language="C#" Debug="true" Service="WcfServiceLibrary1.OrderService" %>