티스토리 뷰

1. Self Hosting 

Self Hosting이란 서비스를 .exe 형태로 제공하는 형태를 말한다. 다른 형태로 제공하는 것보다 서비스를 상세하게 제어 할 수 있는 특성은 있으나 서비스의 제공에 약간의 코딩이 따르는 단점이 있다. 

2. Self Hosting 방식의 서비스의 작성

1) Self Hosting Console Type 프로젝트의 생성

   2) Self Hosting에서 사용할 서비스를 추가  

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;


namespace WCFHostingConsole
{
    [ServiceContract]
    public interface IWCFHostingConsole
    {
        [OperationContract]
        string ServiceName();

        [OperationContract]
        string ServiceVersion();

        [OperationContract]
        string HelloService(string name);

    }

    public class WCFHostingConsole:IWCFHostingConsole
    {
        public string ServiceName()
        {
            return "WCFHostingConsole";
        }

        public string ServiceVersion()
        {
            return "0.0.0.1";
        }

        public string HelloService(string name)
        {
            string result = "Hello " + name;
            return result;
        }
    }
}

3) Hosting Service를 실행할 프로그램을 작성 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
using System.ServiceModel.Description;
using WCFHostingConsole;


namespace WCFHostingConsoleType
{
    class Program
    {
        static void Main(string[] args)
        {
            Uri HelloUri = new Uri("http://localhost:8090/WCFHostingConsole");
            ServiceHost host = new ServiceHost(typeof(WCFHostingConsole.WCFHostingConsole), HelloUri);
            host.AddServiceEndpoint(typeof(WCFHostingConsole.IWCFHostingConsole), new WSHttpBinding(), "");
            ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
            smb.HttpGetEnabled = true;
            host.Description.Behaviors.Add(smb);

            host.Open();
            Console.WriteLine("Service is host at " + DateTime.Now.ToString());
            Console.WriteLine("Host is running ... Plase key to Stop");
            Console.ReadLine();

        }
    }
}

4) Self Hosting 프로그램 가동
Console Command에서 WCFHostingConsoleType.exe를 실행하면 아래와 같은 메시지를 볼 수 있다.

3. 클라이언트에서 접속 테스트 

  

'C# Language > C# NetCore' 카테고리의 다른 글

Open SSL 사용 방법  (0) 2021.08.09
[PLC] PLC 연계 프로그램  (0) 2019.12.18
[NetCore] IIS를 사용하여 배포하기  (2) 2019.11.28
[WCF] 1. WCF 개요(WCF Overview)  (0) 2019.10.02
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함