MSDN Magazine - June 2008 - (Page 47) runtime to create the communication layer, known as the channel stack, for sending and receiving messages. The objects in the channel stack perform the network communication, and they determine how security and other protocols are implemented for a particular endpoint. On the listener side, the RelayBinding enables you to expose an endpoint that will be accessible through a global URI supported by BizTalk Connectivity Services. When an endpoint using RelayBinding has been opened, the URI will be registered with BizTalk Connectivity Services and from that point forward any authorized client will be able to send messages to that global URI using a similarly configured client. BizTalk Connectivity Services then becomes the conduit for communication between those two endpoints. ServiceHost sh = new ServiceHost(typeof(SalesService)); sh.AddServiceEndpoint(typeof(ISalesService), new RelayBinding(), "sb://connect.biztalk.net/services/contososervices/SalesService"); sh.Open(); As you can see, in order to expose the service through BizTalk Services, all we have to do is change one line of code—the call to ServiceHost.AddServiceEndpoint. Instead of NetTcpBinding, we use the RelayBinding, which in turn uses BizTalk Connectivity A Typical WCF Application Let’s take a closer look at a simple example. Imagine that we’re a company and we currently expose a WCF service on our internal network that is called from a rich client application. The client application is used by salespeople to process orders. The application calls the service, and then the service initiates the back-end processing necessary to fulfill the order. The service is currently configured with a single endpoint using NetTcpBinding, which enables high-speed connections over TCP/IP. NetTcpBinding is generally the best option for services operating within the firewall. Here’s the code that configures the endpoint and starts the service using the standard ServiceHost: ServiceHost sh = new ServiceHost(typeof(SalesService)); sh.AddServiceEndpoint(typeof(ISalesService), new NetTcpBinding(), "net.tcp://salesservicehost/SalesService"); sh.Open(); One advantage of the WCF programming model is that you can make fundamental communication changes just by changing the binding. Services to expose this endpoint to the world at the specified URI. Messages sent to that address are then relayed to the local SalesService instance. Notice the format of the URI—it begins with the “sb” scheme and is followed by the BizTalk Services host name, which is then followed by “services.” After that, we add the BizTalk Services identity (the account name we’ve set up), in this case it’s contososervices. Then we can add anything we want to the URI in order to make it unique. Here we’ve simply appended SalesService. When you call ServiceHost.Open, the RelayBinding causes WCF to communicate with BizTalk Identity Services in order to authenticate the service identity and to authorize it to listen on the specified URI. The default behavior at this point is for the Windows CardSpace™ selector to appear, asking someone to select a card representing the service’s identity. The fact that a UI appears during authentication is obviously prohibitive for most services since they generally run in headless environments where there isn’t someone logged into the machine. However, we can get around this problem with a little code, which we’ll show you later, so don’t be concerned. For now, we’re just going to select a card that will enable SalesService to begin listening. You can manage which identities are allowed to listen on a particular URI with BizTalk Identity Services. Now let’s look at what it will take to update the client so that it can consume the BizTalk Services endpoint: static void MakeSaleISB(SaleData sd) { string uri = "sb://connect.biztalk.net/services/contososervices/SalesService"; ChannelFactory cf = new ChannelFactory ( new RelayBinding(), new EndpointAddress(uri)); ISalesService service = cf.CreateChannel(); service.EnterSale(sd); } This is standard WCF code. The service implementation is the type SalesService and the contract is ISalesServices. The ServiceEndpoint, created when AddServiceEndpoint is called, uses NetTcpBinding and has an address of net.tcp://salesservicehost/SalesService. Instead of hardcoding the endpoint this way, we could have also configured the endpoint in the application’s configuration file (which is how you’d typically do it). But this sample should be easier to follow by keeping everything in code. Here is a sample client application that then invokes the SalesService to process a sale: static void MakeSale(SaleData sd) { EndpointAddress ea = new EndpointAddress( "net.tcp://salesservicehost/SalesService"); ChannelFactory cf = new ChannelFactory (new NetTcpBinding(), ea); ISalesService service = cf.CreateChannel(); service.EnterSale(sd); } As time goes on, the sales force becomes more mobile, and reports begin coming in that some salespeople aren’t able to connect to process orders when they are out of the office and attached to random networks (some of which don’t allow Virtual Private Network, or VPN, connections). BizTalk Services is able to solve this problem. Let’s see what it takes to expose SalesService via BizTalk Connectivity Services: msdnmagazine.com Notice that the client and service stay exactly the same except for using RelayBinding and specifying the service bus (sb:// ) URI. June 2008 47 http://msdnmagazine.com
Table of Contents Feed for the Digital Edition of MSDN Magazine - June 2008 MSDN Magazine - June 2008 Contents Toolbox CLR Inside Out Cutting Edge Patterns In Practice SAAS Concurrency Robotics Form Filler GUI Library Service Station Foundations Windows With C++ Concurrent Affairs Going Places { End Bracket } MSDN Magazine - June 2008 MSDN Magazine - June 2008 - Contents (Page Cover1) MSDN Magazine - June 2008 - Contents (Page Cover2) MSDN Magazine - June 2008 - Contents (Page 1) MSDN Magazine - June 2008 - Contents (Page 2) MSDN Magazine - June 2008 - Contents (Page 3) MSDN Magazine - June 2008 - Contents (Page 4) MSDN Magazine - June 2008 - Contents (Page 5) MSDN Magazine - June 2008 - Contents (Page 6) MSDN Magazine - June 2008 - Contents (Page 7) MSDN Magazine - June 2008 - Contents (Page 8) MSDN Magazine - June 2008 - Contents (Page 9) MSDN Magazine - June 2008 - Contents (Page 10) MSDN Magazine - June 2008 - Toolbox (Page 11) MSDN Magazine - June 2008 - Toolbox (Page 12) MSDN Magazine - June 2008 - Toolbox (Page 13) MSDN Magazine - June 2008 - Toolbox (Page 14) MSDN Magazine - June 2008 - CLR Inside Out (Page 15) MSDN Magazine - June 2008 - CLR Inside Out (Page 16) MSDN Magazine - June 2008 - CLR Inside Out (Page 17) MSDN Magazine - June 2008 - CLR Inside Out (Page 18) MSDN Magazine - June 2008 - CLR Inside Out (Page 19) MSDN Magazine - June 2008 - CLR Inside Out (Page 20) MSDN Magazine - June 2008 - CLR Inside Out (Page 21) MSDN Magazine - June 2008 - CLR Inside Out (Page 22) MSDN Magazine - June 2008 - CLR Inside Out (Page 23) MSDN Magazine - June 2008 - CLR Inside Out (Page 24) MSDN Magazine - June 2008 - Cutting Edge (Page 25) MSDN Magazine - June 2008 - Cutting Edge (Page 26) MSDN Magazine - June 2008 - Cutting Edge (Page 27) MSDN Magazine - June 2008 - Cutting Edge (Page 28) MSDN Magazine - June 2008 - Cutting Edge (Page 29) MSDN Magazine - June 2008 - Cutting Edge (Page 30) MSDN Magazine - June 2008 - Cutting Edge (Page 31) MSDN Magazine - June 2008 - Cutting Edge (Page 32) MSDN Magazine - June 2008 - Cutting Edge (Page 33) MSDN Magazine - June 2008 - Cutting Edge (Page 34) MSDN Magazine - June 2008 - Cutting Edge (Page 35) MSDN Magazine - June 2008 - Cutting Edge (Page 36) MSDN Magazine - June 2008 - Patterns In Practice (Page 37) MSDN Magazine - June 2008 - Patterns In Practice (Page 38) MSDN Magazine - June 2008 - Patterns In Practice (Page 39) MSDN Magazine - June 2008 - Patterns In Practice (Page 40) MSDN Magazine - June 2008 - Patterns In Practice (Page 41) MSDN Magazine - June 2008 - Patterns In Practice (Page 42) MSDN Magazine - June 2008 - Patterns In Practice (Page 43) MSDN Magazine - June 2008 - SAAS (Page 44) MSDN Magazine - June 2008 - SAAS (Page 45) MSDN Magazine - June 2008 - SAAS (Page 46) MSDN Magazine - June 2008 - SAAS (Page 47) MSDN Magazine - June 2008 - SAAS (Page 48) MSDN Magazine - June 2008 - SAAS (Page 49) MSDN Magazine - June 2008 - SAAS (Page 50) MSDN Magazine - June 2008 - SAAS (Page 51) MSDN Magazine - June 2008 - SAAS (Page 52) MSDN Magazine - June 2008 - SAAS (Page 53) MSDN Magazine - June 2008 - Concurrency (Page 54) MSDN Magazine - June 2008 - Concurrency (Page 55) MSDN Magazine - June 2008 - Concurrency (Page 56) MSDN Magazine - June 2008 - Concurrency (Page 57) MSDN Magazine - June 2008 - Concurrency (Page 58) MSDN Magazine - June 2008 - Concurrency (Page 59) MSDN Magazine - June 2008 - Concurrency (Page 60) MSDN Magazine - June 2008 - Concurrency (Page 61) MSDN Magazine - June 2008 - Concurrency (Page 62) MSDN Magazine - June 2008 - Concurrency (Page 63) MSDN Magazine - June 2008 - Robotics (Page 64) MSDN Magazine - June 2008 - Robotics (Page 65) MSDN Magazine - June 2008 - Robotics (Page 66) MSDN Magazine - June 2008 - Robotics (Page 67) MSDN Magazine - June 2008 - Robotics (Page 68) MSDN Magazine - June 2008 - Robotics (Page 69) MSDN Magazine - June 2008 - Robotics (Page 70) MSDN Magazine - June 2008 - Robotics (Page 71) MSDN Magazine - June 2008 - Robotics (Page 72) MSDN Magazine - June 2008 - Robotics (Page 73) MSDN Magazine - June 2008 - Robotics (Page 74) MSDN Magazine - June 2008 - Robotics (Page 75) MSDN Magazine - June 2008 - Robotics (Page 76) MSDN Magazine - June 2008 - Robotics (Page 77) MSDN Magazine - June 2008 - Robotics (Page 78) MSDN Magazine - June 2008 - Form Filler (Page 79) MSDN Magazine - June 2008 - Form Filler (Page 80) MSDN Magazine - June 2008 - Form Filler (Page 81) MSDN Magazine - June 2008 - Form Filler (Page 82) MSDN Magazine - June 2008 - Form Filler (Page 83) MSDN Magazine - June 2008 - Form Filler (Page 84) MSDN Magazine - June 2008 - Form Filler (Page 85) MSDN Magazine - June 2008 - GUI Library (Page 86) MSDN Magazine - June 2008 - GUI Library (Page 87) MSDN Magazine - June 2008 - GUI Library (Page 88) MSDN Magazine - June 2008 - GUI Library (Page 89) MSDN Magazine - June 2008 - GUI Library (Page 90) MSDN Magazine - June 2008 - GUI Library (Page 91) MSDN Magazine - June 2008 - GUI Library (Page 92) MSDN Magazine - June 2008 - GUI Library (Page 93) MSDN Magazine - June 2008 - GUI Library (Page 94) MSDN Magazine - June 2008 - GUI Library (Page 95) MSDN Magazine - June 2008 - GUI Library (Page 96) MSDN Magazine - June 2008 - Service Station (Page 97) MSDN Magazine - June 2008 - Service Station (Page 98) MSDN Magazine - June 2008 - Service Station (Page 99) MSDN Magazine - June 2008 - Service Station (Page 100) MSDN Magazine - June 2008 - Service Station (Page 101) MSDN Magazine - June 2008 - Service Station (Page 102) MSDN Magazine - June 2008 - Service Station (Page 103) MSDN Magazine - June 2008 - Service Station (Page 104) MSDN Magazine - June 2008 - Foundations (Page 105) MSDN Magazine - June 2008 - Foundations (Page 106) MSDN Magazine - June 2008 - Foundations (Page 107) MSDN Magazine - June 2008 - Foundations (Page 108) MSDN Magazine - June 2008 - Foundations (Page 109) MSDN Magazine - June 2008 - Foundations (Page 110) MSDN Magazine - June 2008 - Foundations (Page 111) MSDN Magazine - June 2008 - Foundations (Page 112) MSDN Magazine - June 2008 - Windows With C++ (Page 113) MSDN Magazine - June 2008 - Windows With C++ (Page 114) MSDN Magazine - June 2008 - Windows With C++ (Page 115) MSDN Magazine - June 2008 - Windows With C++ (Page 116) MSDN Magazine - June 2008 - Windows With C++ (Page 117) MSDN Magazine - June 2008 - Windows With C++ (Page 118) MSDN Magazine - June 2008 - Concurrent Affairs (Page 119) MSDN Magazine - June 2008 - Concurrent Affairs (Page 120) MSDN Magazine - June 2008 - Concurrent Affairs (Page 121) MSDN Magazine - June 2008 - Concurrent Affairs (Page 122) MSDN Magazine - June 2008 - Concurrent Affairs (Page 123) MSDN Magazine - June 2008 - Concurrent Affairs (Page 124) MSDN Magazine - June 2008 - Concurrent Affairs (Page 125) MSDN Magazine - June 2008 - Concurrent Affairs (Page 126) MSDN Magazine - June 2008 - Going Places (Page 127) MSDN Magazine - June 2008 - Going Places (Page 128) MSDN Magazine - June 2008 - Going Places (Page 129) MSDN Magazine - June 2008 - Going Places (Page 130) MSDN Magazine - June 2008 - Going Places (Page 131) MSDN Magazine - June 2008 - { End Bracket } (Page 132) MSDN Magazine - June 2008 - { End Bracket } (Page Cover3) MSDN Magazine - June 2008 - { End Bracket } (Page Cover4)
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.