첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestSolution.zip
다운로드

[TestServer 프로젝트]

▶ ISimpleService.cs

using System.ServiceModel;

namespace TestServer
{
    /// <summary>
    /// 단순 서비스
    /// </summary>
    [ServiceContract]
    public interface ISimpleService
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        #region 작업 하기 - DoWork()

        /// <summary>
        /// 작업 하기
        /// </summary>
        [OperationContract(IsOneWay = true)]
        void DoWork();

        #endregion
    }
}

 

728x90

 

▶ SimpleService.cs

using System;
using System.ServiceModel;
using System.Threading;

namespace TestServer
{
    [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerCall)]
    public class SimpleService : ISimpleService
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 작업 하기 - DoWork()

        /// <summary>
        /// 작업 하기
        /// </summary>
        public void DoWork()
        {
            Thread.Sleep(1000);

            Console.WriteLine
            (
                "[{0}] {1} 스레드가 요구를 처리했습니다.",
                DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                Thread.CurrentThread.ManagedThreadId
            );
        }

        #endregion
    }
}

 

300x250

 

▶ Program.cs

using System;
using System.ServiceModel;
 
namespace TestServer
{
    /// <summary>
    /// 프로그램
    /// </summary>
    class Program
    {
        ////////////////////////////////////////////////////////////////////////////////////////// Method
        //////////////////////////////////////////////////////////////////////////////// Static
        ////////////////////////////////////////////////////////////////////// Private
 
        #region 프로그램 시작하기 - Main()
 
        /// <summary>
        /// 프로그램 시작하기
        /// </summary>
        private static void Main()
        {
            using(ServiceHost serviceHost = new ServiceHost(typeof(SimpleService)))
            {
                serviceHost.Open();
 
                Console.WriteLine("서버가 시작되었습니다 : " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
 
                Console.ReadKey(true);
            }
        }
 
        #endregion
    }
}

 

▶ App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior name="mexBehavior">
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceThrottling
                        maxConcurrentCalls="3"
                        maxConcurrentInstances="3"
                        maxConcurrentSessions="100" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <services>
            <service name="TestServer.SimpleService" behaviorConfiguration="mexBehavior">
                <endpoint
                    address="SimpleService"
                    binding="basicHttpBinding"
                    contract="TestServer.ISimpleService" />
                <host>
                    <baseAddresses>
                        <add baseAddress="http://localhost:8080" />
                    </baseAddresses>
                </host>
            </service>
        </services>
    </system.serviceModel>
</configuration>

 

[TestClient 프로젝트]

▶ Program.cs

using System;
using System.Threading;

using TestClient.SimpleService;

namespace TestClient
{
    /// <summary>
    /// 프로그램
    /// </summary>
    class Program
    {
        #region 프로그램 시작하기 - Main()

        /// <summary>
        /// 프로그램 시작하기
        /// </summary>
        private static void Main()
        {
            Console.WriteLine("작업 요청을 시작하기 위해 아무 키나 눌러 주시기 바랍니다.");

            Console.ReadKey(true);

            SimpleServiceClient client = new SimpleServiceClient("BasicHttpBinding_ISimpleService");

            for(int i = 1; i <= 100; i++)
            {
                Console.WriteLine("[{0}] {1}번 작업을 요청합니다.", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), i);

                Thread thread = new Thread(client.DoWork);

                thread.Start();
            }
        }

        #endregion
    }
}

 

▶ App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_ISimpleService" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint name="BasicHttpBinding_ISimpleService"
                address="http://localhost:8080/SimpleService"
                binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_ISimpleService"
                contract="SimpleService.ISimpleService" />
        </client>
    </system.serviceModel>
</configuration>
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요