From 4a7924d9e9a666340d09d313662ff7135bb3142d Mon Sep 17 00:00:00 2001 From: syneffort Date: Fri, 10 May 2024 11:52:39 +0900 Subject: [PATCH] wcf remoting --- DataTableRemoting/DataTableRemoting.sln | 31 ++++++++ .../DataTableWCFClient/App.config | 6 ++ .../DataTableWCFClient.csproj | 60 +++++++++++++++ .../DataTableWCFClient/Program.cs | 55 ++++++++++++++ .../Properties/AssemblyInfo.cs | 36 +++++++++ DataTableRemoting/DataTableWCFHost/App.config | 6 ++ .../DataTableWCFHost/DataTableWCFHost.csproj | 70 ++++++++++++++++++ DataTableRemoting/DataTableWCFHost/Program.cs | 29 ++++++++ .../Properties/AssemblyInfo.cs | 36 +++++++++ .../DataTableWCFHost/Properties/app.manifest | 73 +++++++++++++++++++ .../DataTableWCFService/DataManager.cs | 27 +++++++ .../DataTableWCFService/DataTableService.cs | 24 ++++++ .../DataTableWCFService.csproj | 51 +++++++++++++ .../DataTableWCFService/IDataTableService.cs | 20 +++++ .../Properties/AssemblyInfo.cs | 36 +++++++++ 15 files changed, 560 insertions(+) create mode 100644 DataTableRemoting/DataTableWCFClient/App.config create mode 100644 DataTableRemoting/DataTableWCFClient/DataTableWCFClient.csproj create mode 100644 DataTableRemoting/DataTableWCFClient/Program.cs create mode 100644 DataTableRemoting/DataTableWCFClient/Properties/AssemblyInfo.cs create mode 100644 DataTableRemoting/DataTableWCFHost/App.config create mode 100644 DataTableRemoting/DataTableWCFHost/DataTableWCFHost.csproj create mode 100644 DataTableRemoting/DataTableWCFHost/Program.cs create mode 100644 DataTableRemoting/DataTableWCFHost/Properties/AssemblyInfo.cs create mode 100644 DataTableRemoting/DataTableWCFHost/Properties/app.manifest create mode 100644 DataTableRemoting/DataTableWCFService/DataManager.cs create mode 100644 DataTableRemoting/DataTableWCFService/DataTableService.cs create mode 100644 DataTableRemoting/DataTableWCFService/DataTableWCFService.csproj create mode 100644 DataTableRemoting/DataTableWCFService/IDataTableService.cs create mode 100644 DataTableRemoting/DataTableWCFService/Properties/AssemblyInfo.cs diff --git a/DataTableRemoting/DataTableRemoting.sln b/DataTableRemoting/DataTableRemoting.sln index 11638c4..6473c36 100644 --- a/DataTableRemoting/DataTableRemoting.sln +++ b/DataTableRemoting/DataTableRemoting.sln @@ -3,10 +3,41 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.9.34728.123 MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataTableWCFService", "DataTableWCFService\DataTableWCFService.csproj", "{07A3D554-0C5E-4A63-A1B1-2D48165701A4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataTableWCFHost", "DataTableWCFHost\DataTableWCFHost.csproj", "{6E02E64B-D7C0-4593-8CCF-75D680AEB188}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataTableWCFClient", "DataTableWCFClient\DataTableWCFClient.csproj", "{2BC29718-BCFE-4069-881A-595AC1688F8A}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WCF", "WCF", "{35D8B24C-91B6-47F4-AEBC-1FEF7FCF2866}" +EndProject Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {07A3D554-0C5E-4A63-A1B1-2D48165701A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {07A3D554-0C5E-4A63-A1B1-2D48165701A4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {07A3D554-0C5E-4A63-A1B1-2D48165701A4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {07A3D554-0C5E-4A63-A1B1-2D48165701A4}.Release|Any CPU.Build.0 = Release|Any CPU + {6E02E64B-D7C0-4593-8CCF-75D680AEB188}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6E02E64B-D7C0-4593-8CCF-75D680AEB188}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6E02E64B-D7C0-4593-8CCF-75D680AEB188}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6E02E64B-D7C0-4593-8CCF-75D680AEB188}.Release|Any CPU.Build.0 = Release|Any CPU + {2BC29718-BCFE-4069-881A-595AC1688F8A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2BC29718-BCFE-4069-881A-595AC1688F8A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2BC29718-BCFE-4069-881A-595AC1688F8A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2BC29718-BCFE-4069-881A-595AC1688F8A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {07A3D554-0C5E-4A63-A1B1-2D48165701A4} = {35D8B24C-91B6-47F4-AEBC-1FEF7FCF2866} + {6E02E64B-D7C0-4593-8CCF-75D680AEB188} = {35D8B24C-91B6-47F4-AEBC-1FEF7FCF2866} + {2BC29718-BCFE-4069-881A-595AC1688F8A} = {35D8B24C-91B6-47F4-AEBC-1FEF7FCF2866} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {659C8570-938B-451A-8E1F-087AA1B1F50D} EndGlobalSection diff --git a/DataTableRemoting/DataTableWCFClient/App.config b/DataTableRemoting/DataTableWCFClient/App.config new file mode 100644 index 0000000..193aecc --- /dev/null +++ b/DataTableRemoting/DataTableWCFClient/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/DataTableRemoting/DataTableWCFClient/DataTableWCFClient.csproj b/DataTableRemoting/DataTableWCFClient/DataTableWCFClient.csproj new file mode 100644 index 0000000..2222f57 --- /dev/null +++ b/DataTableRemoting/DataTableWCFClient/DataTableWCFClient.csproj @@ -0,0 +1,60 @@ + + + + + Debug + AnyCPU + {2BC29718-BCFE-4069-881A-595AC1688F8A} + Exe + DataTableWCFClient + DataTableWCFClient + v4.8 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + {07a3d554-0c5e-4a63-a1b1-2d48165701a4} + DataTableWCFService + + + + \ No newline at end of file diff --git a/DataTableRemoting/DataTableWCFClient/Program.cs b/DataTableRemoting/DataTableWCFClient/Program.cs new file mode 100644 index 0000000..72755bf --- /dev/null +++ b/DataTableRemoting/DataTableWCFClient/Program.cs @@ -0,0 +1,55 @@ +using DataTableWCFService; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Runtime.InteropServices; +using System.ServiceModel; +using System.Text; +using System.Threading.Tasks; +using System.Timers; + +namespace DataTableWCFClient +{ + internal class Program + { + static Timer _mainTimer; + static IDataTableService _proxy; + + static void Main(string[] args) + { + Uri baseAddress = new Uri("http://10.233.101.136:9207/DataTableService"); + EndpointAddress endpointAddress = new EndpointAddress(baseAddress); + + BasicHttpBinding binding = new BasicHttpBinding(); + ChannelFactory factory = new ChannelFactory(binding, endpointAddress); + _proxy = factory.CreateChannel(); + + _mainTimer = new Timer(); + _mainTimer.Interval = 5000; + _mainTimer.Elapsed += _mainTimer_Elapsed; + _mainTimer.Start(); + + Console.WriteLine("Press to exit."); + Console.ReadLine(); + + _mainTimer.Elapsed -= _mainTimer_Elapsed; + _mainTimer.Stop(); + + ((IClientChannel)_proxy).Close(); + } + + private static void _mainTimer_Elapsed(object sender, ElapsedEventArgs e) + { + DataTable dataTable = _proxy.GetDataTable(); + foreach (DataRow row in dataTable.Rows) + { + Console.WriteLine($"ID: {row["ID"]}, Name: {row["Name"]}"); + } + + Random rand = new Random(); + int id = rand.Next(1000, 5001); + _proxy.UpdateDataTable(id, $"New user {id.ToString("####")}"); + } + } +} diff --git a/DataTableRemoting/DataTableWCFClient/Properties/AssemblyInfo.cs b/DataTableRemoting/DataTableWCFClient/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..ca167cf --- /dev/null +++ b/DataTableRemoting/DataTableWCFClient/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("DataTableWCFClient")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("DataTableWCFClient")] +[assembly: AssemblyCopyright("Copyright © 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("2bc29718-bcfe-4069-881a-595ac1688f8a")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를 +// 기본값으로 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/DataTableRemoting/DataTableWCFHost/App.config b/DataTableRemoting/DataTableWCFHost/App.config new file mode 100644 index 0000000..193aecc --- /dev/null +++ b/DataTableRemoting/DataTableWCFHost/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/DataTableRemoting/DataTableWCFHost/DataTableWCFHost.csproj b/DataTableRemoting/DataTableWCFHost/DataTableWCFHost.csproj new file mode 100644 index 0000000..d35e9a3 --- /dev/null +++ b/DataTableRemoting/DataTableWCFHost/DataTableWCFHost.csproj @@ -0,0 +1,70 @@ + + + + + Debug + AnyCPU + {6E02E64B-D7C0-4593-8CCF-75D680AEB188} + Exe + DataTableWCFHost + DataTableWCFHost + v4.8 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + LocalIntranet + + + false + + + Properties\app.manifest + + + + + + + + + + + + + + + + + + + + + + + {07a3d554-0c5e-4a63-a1b1-2d48165701a4} + DataTableWCFService + + + + \ No newline at end of file diff --git a/DataTableRemoting/DataTableWCFHost/Program.cs b/DataTableRemoting/DataTableWCFHost/Program.cs new file mode 100644 index 0000000..bb93095 --- /dev/null +++ b/DataTableRemoting/DataTableWCFHost/Program.cs @@ -0,0 +1,29 @@ +using DataTableWCFService; +using System; +using System.Collections.Generic; +using System.Linq; +using System.ServiceModel; +using System.Text; +using System.Threading.Tasks; + +namespace DataTableWCFHost +{ + internal class Program + { + static void Main(string[] args) + { + Uri baseAddress = new Uri("http://localhost:9207/DataTableService"); + using (ServiceHost host = new ServiceHost(typeof(DataTableService), baseAddress)) + { + host.AddServiceEndpoint(typeof(IDataTableService), new BasicHttpBinding(), ""); + host.Open(); + + Console.WriteLine($"The service is ready at {baseAddress}"); + Console.WriteLine("Press to stop the service"); + Console.ReadLine(); + + host.Close(); + } + } + } +} diff --git a/DataTableRemoting/DataTableWCFHost/Properties/AssemblyInfo.cs b/DataTableRemoting/DataTableWCFHost/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..fe8dc3b --- /dev/null +++ b/DataTableRemoting/DataTableWCFHost/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("DataTableWCFHost")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("DataTableWCFHost")] +[assembly: AssemblyCopyright("Copyright © 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("6e02e64b-d7c0-4593-8ccf-75d680aeb188")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를 +// 기본값으로 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/DataTableRemoting/DataTableWCFHost/Properties/app.manifest b/DataTableRemoting/DataTableWCFHost/Properties/app.manifest new file mode 100644 index 0000000..5c19d8d --- /dev/null +++ b/DataTableRemoting/DataTableWCFHost/Properties/app.manifest @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DataTableRemoting/DataTableWCFService/DataManager.cs b/DataTableRemoting/DataTableWCFService/DataManager.cs new file mode 100644 index 0000000..b079fb3 --- /dev/null +++ b/DataTableRemoting/DataTableWCFService/DataManager.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataTableWCFService +{ + public class DataManager + { + public static DataManager Instance = new DataManager(); + + public DataManager() + { + if (Instance == null) + { + _dataTable = new DataTable("SampleTable"); + _dataTable.Columns.Add("ID", typeof(int)); + _dataTable.Columns.Add("Name", typeof(string)); + } + } + + DataTable _dataTable; + public DataTable DataTable { get { return _dataTable; } } + } +} diff --git a/DataTableRemoting/DataTableWCFService/DataTableService.cs b/DataTableRemoting/DataTableWCFService/DataTableService.cs new file mode 100644 index 0000000..8089acb --- /dev/null +++ b/DataTableRemoting/DataTableWCFService/DataTableService.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace DataTableWCFService +{ + public class DataTableService : IDataTableService + { + public DataTable GetDataTable() + { + return DataManager.Instance.DataTable; + } + + public void UpdateDataTable(int id, string name) + { + DataManager.Instance.DataTable.Rows.Add(id, name); + DataManager.Instance.DataTable.AcceptChanges(); + } + } +} diff --git a/DataTableRemoting/DataTableWCFService/DataTableWCFService.csproj b/DataTableRemoting/DataTableWCFService/DataTableWCFService.csproj new file mode 100644 index 0000000..c28b3be --- /dev/null +++ b/DataTableRemoting/DataTableWCFService/DataTableWCFService.csproj @@ -0,0 +1,51 @@ + + + + + Debug + AnyCPU + {07A3D554-0C5E-4A63-A1B1-2D48165701A4} + Library + Properties + DataTableWCFService + DataTableWCFService + v4.8 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DataTableRemoting/DataTableWCFService/IDataTableService.cs b/DataTableRemoting/DataTableWCFService/IDataTableService.cs new file mode 100644 index 0000000..777f78d --- /dev/null +++ b/DataTableRemoting/DataTableWCFService/IDataTableService.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.ServiceModel; +using System.Text; +using System.Threading.Tasks; + +namespace DataTableWCFService +{ + [ServiceContract] + public interface IDataTableService + { + [OperationContract] + DataTable GetDataTable(); + + [OperationContract] + void UpdateDataTable(int id, string name); + } +} diff --git a/DataTableRemoting/DataTableWCFService/Properties/AssemblyInfo.cs b/DataTableRemoting/DataTableWCFService/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..5e47368 --- /dev/null +++ b/DataTableRemoting/DataTableWCFService/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("DataTableWCFService")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("DataTableWCFService")] +[assembly: AssemblyCopyright("Copyright © 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("07a3d554-0c5e-4a63-a1b1-2d48165701a4")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를 +// 기본값으로 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")]