いろいろ備忘録日記

主に .NET とか Go とか Flutter とか Python絡みのメモを公開しています。

WCF入門-015 (基本的なサンプル, IIS, WAS, net.pipeのWCFサービスをホスト)


IIS上でnet.pipeのWCFサービスのホストについて。
net.pipeのWCFサービスをホストするためには、IISでWASが有効になっていないと動作しません。
やり方は、前回のnet.tcpの場合とほぼ同じです。


WASの有効化については、以前の記事をご参照ください。

以下、svcファイル.

<%@ ServiceHost Language="C#" Debug="true" Service="WCFNamedPipeHost.MyService" %>

using System;
using System.Collections.Generic;
using System.ServiceModel;

namespace WCFNamedPipeHost
{
  [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="WCFNamedPipeHost.MyService" 
               behaviorConfiguration="MyServiceBehavior">
        <endpoint address="" 
                  binding="netNamedPipeBinding" 
                  contract="WCFNamedPipeHost.IMyService" />
        <endpoint address="mex" 
                  binding="mexNamedPipeBinding" 
                  contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MyServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug    includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>


後は、IISマネージャにて、該当Webアプリの有効プロトコルに「net.pipe」を追加し
WcfTestClientなどで、

net.pipe://localhost/WCFNamedPipeHost/MyService.svc

などとすると、動作していることが確認できます。


サンプルは以下の場所にアップしてあります。
https://sites.google.com/site/gsfzero1/Home/WCFSample-014.zip?attredirects=0&d=1



================================
過去の記事については、以下のページからご参照下さい。