{"id":566,"date":"2013-07-29T15:33:06","date_gmt":"2013-07-29T06:33:06","guid":{"rendered":"http:\/\/astel-labs.net\/blog\/diary\/?p=566"},"modified":"2013-07-29T18:01:19","modified_gmt":"2013-07-29T09:01:19","slug":"29-1","status":"publish","type":"post","link":"https:\/\/astel-labs.net\/blog\/diary\/2013\/07\/29-1.html","title":{"rendered":"WCF &#8211; ChannelFactory \u3092\u5229\u7528\u3057\u305f\u30b5\u30fc\u30d3\u30b9\u547c\u3073\u51fa\u3057"},"content":{"rendered":"<p>WCF \u3092\u5229\u7528\u3057\u3066\u30b5\u30fc\u30d3\u30b9\u3092\u516c\u958b\u3059\u308b\u969b\u306b\u3001\u516c\u958b\u3057\u305f\u30b5\u30fc\u30d3\u30b9\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u65b9\u6cd5\u3068\u3057\u3066\u30b5\u30f3\u30d7\u30eb\u3067\u3088\u304f\u7d39\u4ecb\u3055\u308c\u308b\u300c\u30b5\u30fc\u30d3\u30b9\u53c2\u7167\u306e\u8ffd\u52a0\u300d\u3067\u3059\u304c\u3001\u30c7\u30d0\u30c3\u30b0\u74b0\u5883\u3068\u672c\u756a\u74b0\u5883\u306e\u5207\u308a\u66ff\u3048\u306b\u3088\u308a\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u30a2\u30c9\u30ec\u30b9\u304c\u7570\u306a\u308b\u5834\u5408\u306b\u306f\u3001\u30b5\u30fc\u30d3\u30b9\u3092\u767a\u884c\u3059\u308b\u305f\u3073\u306b\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u30a2\u30c9\u30ec\u30b9\u3092\u66f8\u304d\u63db\u3048\u308b\u306a\u3069\u624b\u9593\u304c\u304b\u304b\u308a\u4f7f\u3044\u52dd\u624b\u304c\u3088\u304f\u306a\u3044\u305f\u3081\u3001\u901a\u5e38 ChannelFactory \u304c\u5229\u7528\u3055\u308c\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/astel-labs.net\/blog\/diary\/images\/2013\/07\/29-1_01.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-567\" alt=\"29-1_01\" src=\"http:\/\/astel-labs.net\/blog\/diary\/images\/2013\/07\/29-1_01-300x190.jpg\" width=\"300\" height=\"190\" srcset=\"https:\/\/astel-labs.net\/blog\/diary\/images\/2013\/07\/29-1_01-300x190.jpg 300w, https:\/\/astel-labs.net\/blog\/diary\/images\/2013\/07\/29-1_01.jpg 492w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a>\u00a0\u00a0\u00a0 <a href=\"http:\/\/astel-labs.net\/blog\/diary\/images\/2013\/07\/29-1_06.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-573\" alt=\"29-1_06\" src=\"http:\/\/astel-labs.net\/blog\/diary\/images\/2013\/07\/29-1_06-300x287.jpg\" width=\"300\" height=\"287\" srcset=\"https:\/\/astel-labs.net\/blog\/diary\/images\/2013\/07\/29-1_06-300x287.jpg 300w, https:\/\/astel-labs.net\/blog\/diary\/images\/2013\/07\/29-1_06.jpg 631w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>\u4eca\u56de\u306f\u3001ChannelFactory \u3092\u5229\u7528\u3057\u3066 WCF \u30b5\u30fc\u30d3\u30b9\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u65b9\u6cd5\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p><!--more--><\/p>\n<p>&nbsp;<\/p>\n<p>\u307e\u305a\u306f\u3001\u7c21\u5358\u306a\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p>\u4f8b\u3068\u3057\u3066\u300eChannelFactorySample\u300f\u3068\u3044\u3046\u540d\u524d\u3067\u300c\u30b3\u30f3\u30bd\u30fc\u30eb\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u300d\u3092\u4f5c\u6210\u3057\u3001\u7d9a\u3044\u3066\u540c\u3058\u30bd\u30ea\u30e5\u30fc\u30b7\u30e7\u30f3\u5185\u306b\u300cWCF \u30b5\u30fc\u30d3\u30b9\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u300d\u3092\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u540d\u524d\u306e\u300eWcfService1\u300f\u3067\u8ffd\u52a0\u3057\u307e\u3059\u3002<br \/>\n\u4eca\u56de\u306f\u3001WCF \u30b5\u30fc\u30d3\u30b9\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306b\u5bfe\u3057\u3066\u306f\u4f55\u3082\u5909\u66f4\u3092\u884c\u3044\u307e\u305b\u3093\u3002<\/p>\n<p>\u30bd\u30ea\u30e5\u30fc\u30b7\u30e7\u30f3\u306e\u69cb\u6210\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/astel-labs.net\/blog\/diary\/images\/2013\/07\/29-1_02.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-568\" alt=\"29-1_02\" src=\"http:\/\/astel-labs.net\/blog\/diary\/images\/2013\/07\/29-1_02-292x300.jpg\" width=\"292\" height=\"300\" srcset=\"https:\/\/astel-labs.net\/blog\/diary\/images\/2013\/07\/29-1_02-292x300.jpg 292w, https:\/\/astel-labs.net\/blog\/diary\/images\/2013\/07\/29-1_02.jpg 372w\" sizes=\"auto, (max-width: 292px) 100vw, 292px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3057\u305f\u3089\u3001ChannelFactorySample \u306e\u53c2\u7167\u8a2d\u5b9a\u306b\u300cWcfService1\u300d\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<br \/>\n\u3053\u306e\u6642\u3001\u4f75\u305b\u3066\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u304b\u3089\u300cSystem.ServiceModel\u300d\u3082\u4e00\u7dd2\u306b\u8ffd\u52a0\u3057\u3066\u304a\u3044\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><a href=\"http:\/\/astel-labs.net\/blog\/diary\/images\/2013\/07\/29-1_03.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-569\" alt=\"29-1_03\" src=\"http:\/\/astel-labs.net\/blog\/diary\/images\/2013\/07\/29-1_03-300x260.jpg\" width=\"300\" height=\"260\" srcset=\"https:\/\/astel-labs.net\/blog\/diary\/images\/2013\/07\/29-1_03-300x260.jpg 300w, https:\/\/astel-labs.net\/blog\/diary\/images\/2013\/07\/29-1_03.jpg 372w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u8a2d\u5b9a\u304c\u3067\u304d\u307e\u3057\u305f\u306e\u3067\u3001\u7d9a\u3044\u3066\u30b3\u30fc\u30c9\u3092\u66f8\u3044\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u300cChannelFactorySample\u300d\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u300cProgram.cs\u300d\u3092\u958b\u304d\u3001Main \u30e1\u30bd\u30c3\u30c9\u5185\u306b\u51e6\u7406\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8a18\u8f09\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: csharp; gutter: true\">using System;\r\nusing System.ServiceModel;\r\nusing WcfService1;\r\n\r\nnamespace ChannelFactorySample\r\n{\r\n    class Program\r\n    {\r\n        static void Main(string[] args)\r\n        {\r\n            try\r\n            {\r\n                \/\/ \u30c1\u30e3\u30cd\u30eb\u30d5\u30a1\u30af\u30c8\u30ea\u306e\u4f5c\u6210\r\n                var channel = new ChannelFactory&lt;IService1&gt;(\r\n                    new BasicHttpBinding(),\r\n                    new EndpointAddress(&quot;http:\/\/localhost:53461\/Service1.svc&quot;));\r\n                if (channel == null)\r\n                    throw new Exception(&quot;\u30c1\u30e3\u30cd\u30eb\u30d5\u30a1\u30af\u30c8\u30ea\u306e\u4f5c\u6210\u306b\u5931\u6557\u3002&quot;);\r\n\r\n                \/\/ \u30c1\u30e3\u30cd\u30eb\u306e\u53d6\u5f97\r\n                var service = channel.CreateChannel();\r\n                if (service == null)\r\n                    throw new Exception(&quot;\u30c1\u30e3\u30cd\u30eb\u306e\u4f5c\u6210\u306b\u5931\u6557\u3002&quot;);\r\n\r\n                \/\/ \u30b5\u30fc\u30d3\u30b9\u306e\u5b9f\u884c\r\n                Console.WriteLine(&quot;ExecuteService=&gt; &quot; + service.GetData(5));\r\n            }\r\n            catch (Exception ex)\r\n            {\r\n                Console.WriteLine(ex.Message);\r\n            }\r\n\r\n            \/\/ \u30ad\u30fc\u304c\u62bc\u4e0b\u3055\u308c\u308b\u307e\u3067\u5f85\u6a5f\u3059\u308b\r\n            Console.ReadKey();\r\n        }\r\n    }\r\n}<\/pre>\n<p>\u4eca\u56de\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u306f\u3001ChannelFactory \u306e\u4f5c\u6210\u306b BasicHttpBinding \u3092\u4f7f\u7528\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u307e\u305f\u3001EndpointAddress \u3067\u6307\u5b9a\u3057\u3066\u3044\u308b\u30a2\u30c9\u30ec\u30b9\u306f\u3001\u300cWcfService1\u300d\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u300cService1.svc\u300d\u3092\u53f3\u30af\u30ea\u30c3\u30af\u3057\u3066\u300c\u30d6\u30e9\u30a6\u30b6\u30fc\u3067\u8868\u793a\u300d\u3092\u9078\u629e\u3057\u3066\u8868\u793a\u3055\u308c\u305f\u30d6\u30e9\u30a6\u30b6\u306e\u3001\u30a2\u30c9\u30ec\u30b9\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/astel-labs.net\/blog\/diary\/images\/2013\/07\/29-1_04.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-570\" alt=\"29-1_04\" src=\"http:\/\/astel-labs.net\/blog\/diary\/images\/2013\/07\/29-1_04-300x137.jpg\" width=\"300\" height=\"137\" srcset=\"https:\/\/astel-labs.net\/blog\/diary\/images\/2013\/07\/29-1_04-300x137.jpg 300w, https:\/\/astel-labs.net\/blog\/diary\/images\/2013\/07\/29-1_04.jpg 426w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a>\u00a0\u00a0\u00a0 <a href=\"http:\/\/astel-labs.net\/blog\/diary\/images\/2013\/07\/29-1_05.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-571\" alt=\"29-1_05\" src=\"http:\/\/astel-labs.net\/blog\/diary\/images\/2013\/07\/29-1_05-300x186.jpg\" width=\"300\" height=\"186\" srcset=\"https:\/\/astel-labs.net\/blog\/diary\/images\/2013\/07\/29-1_05-300x186.jpg 300w, https:\/\/astel-labs.net\/blog\/diary\/images\/2013\/07\/29-1_05.jpg 543w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>26\u884c\u76ee\u3067\u300cIService1\u300d\u3067\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u300cGetData\u300d\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u30b5\u30fc\u30d3\u30b9\u3068\u3057\u3066\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3059\u306b\u306f\u3001\u30af\u30e9\u30b9\u306b\u300cServiceContract\u300d\u5c5e\u6027\u304c\u4ed8\u52a0\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u3001\u307e\u305f\u30af\u30e9\u30b9\u5185\u306e\u30e1\u30bd\u30c3\u30c9\u306b\u300cOperationContract\u300d\u5c5e\u6027\u304c\u4ed8\u52a0\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u304c\u5fc5\u9808\u3067\u3059\u3002<\/p>\n<pre class=\"brush: csharp; gutter: true\">[ServiceContract]\r\npublic interface IService1\r\n{\r\n\r\n    [OperationContract]\r\n    string GetData(int value);\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>\u4ee5\u4e0a\u306e\u3088\u3046\u306b\u3001\u30b5\u30fc\u30d3\u30b9\u53c2\u7167\u3067\u30b5\u30fc\u30d3\u30b9\u3092\u547c\u3073\u51fa\u3059\u306e\u3068\u540c\u3058\u304f\u3089\u3044\u3001ChannelFactory \u3092\u5229\u7528\u3057\u3066\u7c21\u5358\u306b\u30b5\u30fc\u30d3\u30b9\u3092\u547c\u3073\u51fa\u305b\u308b\u3053\u3068\u304c\u308f\u304b\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>WCF \u3092\u5229\u7528\u3057\u3066\u30b5\u30fc\u30d3\u30b9\u3092\u516c\u958b\u3059\u308b\u969b\u306b\u3001\u516c\u958b\u3057\u305f\u30b5\u30fc\u30d3\u30b9\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u65b9\u6cd5\u3068\u3057\u3066\u30b5\u30f3\u30d7\u30eb\u3067\u3088\u304f\u7d39\u4ecb\u3055\u308c\u308b\u300c\u30b5\u30fc\u30d3\u30b9\u53c2\u7167\u306e\u8ffd\u52a0\u300d\u3067\u3059\u304c\u3001\u30c7\u30d0\u30c3\u30b0\u74b0\u5883\u3068\u672c\u756a\u74b0\u5883\u306e\u5207\u308a\u66ff\u3048\u306b\u3088\u308a\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u30a2\u30c9\u30ec\u30b9\u304c\u7570\u306a\u308b\u5834\u5408\u306b\u306f\u3001\u30b5\u30fc\u30d3 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,12,4],"tags":[],"class_list":["post-566","post","type-post","status-publish","format-standard","hentry","category-c","category-wcf","category-4"],"_links":{"self":[{"href":"https:\/\/astel-labs.net\/blog\/diary\/wp-json\/wp\/v2\/posts\/566","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/astel-labs.net\/blog\/diary\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/astel-labs.net\/blog\/diary\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/astel-labs.net\/blog\/diary\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/astel-labs.net\/blog\/diary\/wp-json\/wp\/v2\/comments?post=566"}],"version-history":[{"count":3,"href":"https:\/\/astel-labs.net\/blog\/diary\/wp-json\/wp\/v2\/posts\/566\/revisions"}],"predecessor-version":[{"id":587,"href":"https:\/\/astel-labs.net\/blog\/diary\/wp-json\/wp\/v2\/posts\/566\/revisions\/587"}],"wp:attachment":[{"href":"https:\/\/astel-labs.net\/blog\/diary\/wp-json\/wp\/v2\/media?parent=566"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/astel-labs.net\/blog\/diary\/wp-json\/wp\/v2\/categories?post=566"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/astel-labs.net\/blog\/diary\/wp-json\/wp\/v2\/tags?post=566"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}