IIS上でnet.tcpのWCFサービスのホストについて。
net.tcpのWCFサービスをホストするためには、IISでWASが有効になっていないと動作しません。
WASの有効化については、以前の記事をご参照ください。
- WCF入門-013 (基本的なサンプル, IIS, WASの有効化, Windows Process Activation Service, 非HTTPプロトコルのサポート, net.tcp, net.pipe, net.msmq)
以下、svcファイル.
<%@ServiceHost Language="C#" Debug="false" Service="WCFTcpHost.MyService"%> using System; using System.Collections.Generic; using System.ServiceModel; namespace WCFTcpHost { [ServiceContract] public interface IMyService { [OperationContract] string GetMessage(string name); } public class MyService : IMyService { public string GetMessage(string name) { return string.Format("Hello. '{0}'", name); } } }
次にweb.configファイル.
<?xml version="1.0" encoding="utf-8"?> <configuration> <system.serviceModel> <services> <service name="WCFTcpHost.MyService" behaviorConfiguration="MyServiceBehavior"> <endpoint address="" binding="netTcpBinding" contract="WCFTcpHost.IMyService" /> <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" /> </service> </services> <behaviors> <serviceBehaviors> <behavior name="MyServiceBehavior"> <!-- MEXバインディングにTCPを利用する場合でも以下の設定は必要. --> <!-- (これを設定しないと「アクティブ化できない」というエラーとなる。) --> <serviceMetadata httpGetEnabled="false" /> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> </configuration>
後は、IISマネージャにて、該当Webアプリの有効プロトコルに「net.tcp」を追加し
WcfTestClientなどで、
net.tcp://localhost/WCFTcpHost/MyService.svc
などとすると、動作していることが確認できます。
サンプルは以下の場所にアップしてあります。
https://sites.google.com/site/gsfzero1/Home/WCFSample-013.zip?attredirects=0&d=1
================================
過去の記事については、以下のページからご参照下さい。
- いろいろ備忘録日記まとめ