{"id":22706,"date":"2021-03-19T11:08:38","date_gmt":"2021-03-19T15:08:38","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/basic-wcf-example-root-by-sayed-ahmed\/"},"modified":"2021-03-19T11:08:38","modified_gmt":"2021-03-19T15:08:38","slug":"basic-wcf-example-root-by-sayed-ahmed","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=22706","title":{"rendered":"Basic WCF Example #Root #By Sayed Ahmed"},"content":{"rendered":"<p>Defining and Implementing a Contract<\/p>\n<pre>using System.ServiceModel;\r\n\r\n\/\/a WCF contract defined using an interface\r\n[ServiceContract]\r\npublic interface IMath\r\n{\r\n    [OperationContract]\r\n    int Add(int x, int y);\r\n}\r\n\r\n\r\n<\/pre>\n<pre>\/\/the service class implements the interface\r\npublic class MathService : IMath\r\n{\r\n    public int Add(int x, int y)\r\n    { return x + y; }\r\n}\r\n\r\n\r\nDefining Endpoints and Starting the Service\r\n\r\n<\/pre>\n<pre>public class WCFServiceApp\r\n{\r\n    public void DefineEndpointImperatively()\r\n    {\r\n        \/\/create a service host for MathService\r\n        ServiceHost sh = new ServiceHost(typeof(MathService));\r\n\r\n        \/\/use the AddEndpoint helper method to\r\n        \/\/create the ServiceEndpoint and add it \r\n        \/\/to the ServiceDescription\r\n        sh.AddServiceEndpoint(\r\n          typeof(IMath), \/\/contract type\r\n          new WSHttpBinding(), \/\/one of the built-in bindings\r\n          \"http:\/\/localhost\/MathService\/Ep1\"); \/\/the endpoint's address\r\n\r\n        \/\/create and open the service runtime\r\n        sh.Open();\r\n\r\n    }\r\n\r\n    public void DefineEndpointInConfig()\r\n    {\r\n        \/\/create a service host for MathService\r\n        ServiceHost sh = new ServiceHost (typeof(MathService));\r\n\r\n        \/\/create and open the service runtime\r\n        sh.Open();\r\n\r\n    }\r\n}\r\n&lt;!-- configuration file used by above code --&gt;\r\n&lt;configuration \r\n   xmlns=\"http:\/\/schemas.microsoft.com\/.NetConfiguration\/v2.0\"&gt;\r\n   &lt;system.serviceModel&gt;\r\n      &lt;services&gt;\r\n         &lt;!-- service element references the service type --&gt;\r\n         &lt;service type=\"MathService\"&gt;\r\n            &lt;!-- endpoint element defines the ABC's of the endpoint --&gt;\r\n              &lt;endpoint \r\n                 address=\"http:\/\/localhost\/MathService\/Ep1\"\r\n                 binding=\"wsHttpBinding\"\r\n                 contract=\"IMath\"\/&gt;\r\n         &lt;\/service&gt;\r\n      &lt;\/services&gt;\r\n   &lt;\/system.serviceModel&gt;\r\n&lt;\/configuration&gt;\r\n\r\n\r\n\r\n<\/pre>\n<h3 class=\"dtH1\">Sending Messages to an Endpoint<\/h3>\n<pre>using System.ServiceModel;\r\n\/\/this contract is generated by svcutil.exe\r\n\/\/from the service's metadata\r\npublic interface IMath\r\n{\r\n    [OperationContract]\r\n    public int Add(int x, int y)\r\n    { return x + y; }\r\n}\r\n\r\n\r\n\/\/this class is generated by svcutil.exe\r\n\/\/from the service's metadata\r\n\/\/generated config is not shown here\r\npublic class MathProxy : IMath\r\n{\r\n    ...\r\n}\r\n\r\npublic class WCFClientApp\r\n{\r\n    public void SendMessageToEndpoint()\r\n    {\r\n        \/\/this uses a proxy class that was\r\n        \/\/created by svcutil.exe from the service's metadata\r\n        MathProxy proxy = new MathProxy();\r\n\r\n        int result = proxy.Add(35, 7);\r\n    }\r\n    public void SendMessageToEndpointUsingChannel()\r\n    {\r\n        \/\/this uses ChannelFactory to create the channel\r\n        \/\/you must specify the address, the binding and \r\n        \/\/the contract type (IMath)\r\n        ChannelFactory&lt;IMath&gt; factory=new ChannelFactory&lt;IMath&gt;(\r\n            new WSHttpBinding(),\r\n            new EndpointAddress(\"http:\/\/localhost\/MathService\/Ep1\"));\r\n        IMath channel=factory.CreateChannel();\r\n        int result=channel.Add(35,7);\r\n        factory.Close();\r\n\r\n    }\r\n}\r\n\r\nReference:\r\n<a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa480210.aspx\">http:\/\/msdn.microsoft.com\/en-us\/library\/aa480210.aspx\r\nhttp:\/\/msdn.microsoft.com\/en-us\/library\/ms731082%28v=vs.110%29.aspx<\/a>\r\n\r\n<\/pre>\n<p> From: http:\/\/sitestree.com\/?p=1305<br \/> Categories:Root, By Sayed Ahmed<br \/>Tags:<br \/> Post Data:2014-08-06 21:04:33<\/p>\n<p>\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com\/' target='new' rel=\"noopener\">https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\t(Big Data, Cloud, Security, Machine Learning): Courses: <a href='http:\/\/Training.SitesTree.com' target='new' rel=\"noopener\"> http:\/\/Training.SitesTree.com<\/a><br \/>\n\t\tIn Bengali: <a href='http:\/\/Bangla.SaLearningSchool.com' target='new' rel=\"noopener\">http:\/\/Bangla.SaLearningSchool.com<\/a><br \/>\n\t\t<a href='http:\/\/SitesTree.com' target='new' rel=\"noopener\">http:\/\/SitesTree.com<\/a><br \/>\n\t\t8112223 Canada Inc.\/JustEtc: <a href='http:\/\/JustEtc.net' target='new' rel=\"noopener\">http:\/\/JustEtc.net (Software\/Web\/Mobile\/Big-Data\/Machine Learning) <\/a><br \/>\n\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com'> https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\tMedium: <a href='https:\/\/medium.com\/@SayedAhmedCanada' target='new' rel=\"noopener\"> https:\/\/medium.com\/@SayedAhmedCanada <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Defining and Implementing a Contract using System.ServiceModel; \/\/a WCF contract defined using an interface [ServiceContract] public interface IMath { [OperationContract] int Add(int x, int y); } \/\/the service class implements the interface public class MathService : IMath { public int Add(int x, int y) { return x + y; } } Defining Endpoints and Starting &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=22706\">Continue reading<\/a><\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1917],"tags":[],"class_list":["post-22706","post","type-post","status-publish","format-standard","hentry","category-fromsitestree-com","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":10541,"url":"http:\/\/bangla.sitestree.com\/?p=10541","url_meta":{"origin":22706,"position":0},"title":"Example illustrating inheritance and abstract classes","author":"","date":"August 29, 2015","format":false,"excerpt":"*********************************** # Example illustrating inheritance and abstract classes. \u00a0\u00a0\u00a0 * Shape.java The parent class (abstract) for all closed, open, curved, and straight-edged shapes. \u00a0\u00a0\u00a0 * Curve.java An (abstract) curved Shape (open or closed). \u00a0\u00a0\u00a0 * StraightEdgedShape.java A Shape with straight edges (open or closed). \u00a0\u00a0\u00a0 * Measurable.java Interface defining classes\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26567,"url":"http:\/\/bangla.sitestree.com\/?p=26567","url_meta":{"origin":22706,"position":1},"title":"Example illustrating inheritance and abstract classes #Programming Code Examples #Java\/J2EE\/J2ME #Object Oriented Programming","author":"Author-Check- Article-or-Video","date":"April 28, 2021","format":false,"excerpt":"*********************************** # Example illustrating inheritance and abstract classes. * Shape.java The parent class (abstract) for all closed, open, curved, and straight-edged shapes. * Curve.java An (abstract) curved Shape (open or closed). * StraightEdgedShape.java A Shape with straight edges (open or closed). * Measurable.java Interface defining classes with measurable areas. *\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10539,"url":"http:\/\/bangla.sitestree.com\/?p=10539","url_meta":{"origin":22706,"position":2},"title":"Example illustrating inheritance and abstract classes","author":"","date":"August 2, 2015","format":false,"excerpt":"illustrating inheritance \u098f\u09ac\u0982 abstract classes \u098f\u09b0 \u0989\u09a6\u09be\u09b9\u09b0\u09a3 Shape.java \u09b8\u09ac, \u09ac\u09a6\u09cd\u09a7 \u0996\u09cb\u09b2\u09be, \u09ac\u09be\u0981\u0995\u09be, \u098f\u09ac\u0982 \u09b8\u09cb\u099c\u09be \u09aa\u09be\u09b0\u09cd\u09b6\u09cd\u09ac\u09c7 \u09a7\u09be\u09b0\u09ac\u09bf\u09b6\u09bf\u09b7\u09cd\u099f \u0986\u0995\u09be\u09b0 \u098f\u09b0 \u099c\u09a8\u09cd\u09af \u09aa\u09cd\u09af\u09be\u09b0\u09c7\u09a8\u09cd\u099f \u0995\u09cd\u09b2\u09be\u09b8 (\u09b8\u09be\u09b0\u09be\u0982\u09b6)\u0964 Curve.java \u098f\u0995\u099f\u09bf (\u09b8\u09be\u09b0\u09be\u0982\u09b6) \u09ac\u09be\u0981\u0995\u09be \u0986\u0995\u09be\u09b0 (\u0996\u09cb\u09b2\u09be \u09ac\u09be \u09ac\u09a8\u09cd\u09a7)\u0964 StraightEdgedShape.java \u09b8\u09b0\u09be\u09b8\u09b0\u09bf \u09a7\u09be\u09b0 \u09b8\u09ae\u09cd\u09ac\u09b2\u09bf\u09a4 \u098f\u0995\u099f\u09bf \u0986\u0995\u09c3\u09a4\u09bf (\u0996\u09cb\u09b2\u09be \u09ac\u09be \u09ac\u09a8\u09cd\u09a7)\u0964 Measurable.java \u09aa\u09b0\u09bf\u09ae\u09be\u09aa\u09af\u09cb\u0997\u09cd\u09af \u098f\u09b2\u09be\u0995\u09be\u09af\u09bc \u0987\u09a8\u09cd\u099f\u09be\u09b0\u09ab\u09c7\u09b8 \u09a1\u09bf\u09ab\u09be\u0987\u09a8\u09bf\u0982 \u0995\u09cd\u09b2\u09be\u09b8\u0964 Circle.java \u098f\u0995\u099f\u09bf \u09ac\u09c3\u09a4\u09cd\u09a4 \u09af\u09be \u0986\u0995\u09be\u09b0\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":65922,"url":"http:\/\/bangla.sitestree.com\/?p=65922","url_meta":{"origin":22706,"position":3},"title":"EJB 3: Stateless Bean #Java Short Notes","author":"Author-Check- Article-or-Video","date":"July 17, 2021","format":false,"excerpt":"No need to maintain the state of a bean between calls. \/\/CalculatorBean.java@Statelesspublic class CalculatorBean implements CalculatorRemote, CalculatorLocal{ public int add(int x, int y) { return x + y; } public int subtract(int x, int y) { return x - y; }}\/\/CalculatorRemote.javaimport javax.ejb.Remote;@Remotepublic interface CalculatorRemote extends Calculator{}\/\/CalculatorLocal.java import javax.ejb.Local;@Localpublic interface CalculatorLocal\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26860,"url":"http:\/\/bangla.sitestree.com\/?p=26860","url_meta":{"origin":22706,"position":4},"title":"Multithreaded Graphics and Double Buffering #Programming Code Examples #Java\/J2EE\/J2ME #Java Threads","author":"Author-Check- Article-or-Video","date":"May 3, 2021","format":false,"excerpt":"ShipSimulation.java Illustrates the basic approach of multithreaded graphics whereas a thread adjusts parameters affecting the appearance of the graphics and then calls repaint to schedule an update of the display. import java.applet.Applet; import java.awt.*; public class ShipSimulation extends Applet implements Runnable { ... public void run() { Ship s; for(int\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10212,"url":"http:\/\/bangla.sitestree.com\/?p=10212","url_meta":{"origin":22706,"position":5},"title":"Multithreaded Graphics and Double Buffering","author":"","date":"August 25, 2015","format":false,"excerpt":"ShipSimulation.java\u00a0 Illustrates the basic approach of multithreaded graphics whereas a thread adjusts parameters affecting the appearance of the graphics and then calls repaint to schedule an update of the display. \u00a0 import java.applet.Applet; import java.awt.*; public class ShipSimulation extends Applet implements Runnable { \u00a0 ... \u00a0 \u00a0 public void run()\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/22706","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=22706"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/22706\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=22706"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=22706"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=22706"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}