1. Trang chủ
  2. » Công Nghệ Thông Tin

Introducing Windows Azure- P42 pdf

5 275 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Nội dung

CHAPTER 6 ■ AZURE .NET SERVICES—SERVICE BUS 198 SoftnetSolutions.RelayService.ShapeController The Draw Shape Controller is another part of this system. The responsibility of this Windows-based application is to select a drawing shape type and publish a message with the type of PostData that contains a string description and the enumeration value for the selected drawing shape. The data contract PostData is defined in Listing 6-12 and implements the IComparable interface to allow the service application to check for selected drawing shape changes from the client drawing controller application. The implementation of this class is straightforward as Listing 6-16 shows. When a button is clicked, a different drawing shape is selected and a new PostData object is created and sent out as part of the publishing message sent from the drawing controller to the shape-drawing application. The component that we use to create out the communication channel is the HybridPublishService we created in the last exercise. Listing 6-16. Implementation of ShapeController using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.ServiceModel; using Microsoft.ServiceBus; namespace SoftnetSolutions.RelayService.ShapeController { using SoftnetSolutions.RelayService.ServiceContract; using SoftnetSolutions.Shape; using SoftnetSolutions.Shape.Draw; public partial class FormController : Form { private IPublishEventService publishEventService = null; private HybridPublishService hybridPublishService = null; private string connectionStatus = "Disconnected"; public FormController() { InitializeComponent(); } public FormController(IPublishEventService publishEventService) { InitializeComponent(); publishEventService = publishEventService; string endpoint = "RelayEndpoint"; hybridPublishService = new HybridPublishService(endpoint); CHAPTER 6 ■ AZURE .NET SERVICES—SERVICE BUS 199 IHybridConnectionStatus hybridConnectionStatus = hybridPublishService.ClientChannel.GetProperty<IHybridConnectionStatus>(); connectionStatus = hybridConnectionStatus.ConnectionState.ToString(); hybridConnectionStatus.ConnectionStateChanged += new EventHandler<HybridConnectionStateChangedArgs>( hybridConnectionStatus ConnectionStateChanged); ( publishEventService as FormDrawShape).Show(); } private void btnCircle Click(object sender, EventArgs e) { PostData shapeData = new PostData(); shapeData.shape = SHAPE TYPE.CIRCLE; PostMessage(shapeData); } private void btnRectangle Click(object sender, EventArgs e) { PostData shapeData = new PostData(); shapeData.shape = SHAPE TYPE.RECTANGLE; PostMessage(shapeData); } private void btnSqure Click(object sender, EventArgs e) { PostData shapeData = new PostData(); shapeData.shape = SHAPE TYPE.SQUARE; PostMessage(shapeData); } private void btnEcllipse Click(object sender, EventArgs e) { PostData shapeData = new PostData(); shapeData.shape = SHAPE TYPE.ELLIPSE; PostMessage(shapeData); } private void hybridConnectionStatus ConnectionStateChanged( object sender, HybridConnectionStateChangedArgs args) { System.Diagnostics.Trace.WriteLine( string.Format( " Connection has been switched from relay to direct connection {0}", Environment.NewLine)); connectionStatus = args.ConnectionState.ToString(); } CHAPTER 6 ■ AZURE .NET SERVICES—SERVICE BUS 200 private void PostMessage(PostData postData) { postData.Message = string.Format("[{0}]:Shape Controller select <{1}>", DateTime.Now.ToString(), postData.shape); publishEventService.OnShapeSelectChanged(postData); publishEventService.PostMessage(postData); } private void timer1 Tick(object sender, EventArgs e) { textBoxConnectinStatus.Text = connectionStatus; switch ( connectionStatus) { case "Relayed": textBoxConnectinStatus.ForeColor = Color.Red; break; case "Direct": textBoxConnectinStatus.ForeColor = Color.Lime; break; } } } } Before going any further, we should look at port forwarding when using netTcpRelayBinding with Hybrid mode. This may or may not be a potential issue depending upon the Internet service provider behind the system infrastructure, especially if you are working from a small LAN system or from home. Port Forwarding If the DHCP connection type is used by the local gateway system, port forwarding usually needs to be configured in order that the communication from .NET Service Bus can be routed to the application correctly. How to configure port forwarding depends on the Internet provider your organization has. Port forwarding should be configured to allow Internet access to port 80 using HTTP and port 808 using TCP. Figure 6-11 shows how to configure port forwarding based on the Verizon FIOS gateway. CHAPTER 6 ■ AZURE .NET SERVICES—SERVICE BUS 201 Figure 6-11. An example of port forwarding configuration using Verizon FIOS gateway CHAPTER 6 ■ AZURE .NET SERVICES—SERVICE BUS 202 Change Credential Type To modify the access federation type, modify the configuration file App.config for ShapeController. The boldface lines in Listing 6-17 and Listing 6-18 show how to use the CardSpace and AutomaticRenewal credentials respectively. The most frequently used options of federation are • CardSpace • UserNamePassword • X509Certificate • AutomaticRenewal Listing 6-17. Change the Credential Type to CardSpace in the Configuration File App.config of ShapeController <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="Topic" value="PublishEventService"/> <add key="Solution" value="SoftnetSolutionsServiceBus"/> <add key="password" value="9j!Ns$R8%7"/> </appSettings> <system.serviceModel> <bindings> <netTcpRelayBinding> <binding name="default" connectionMode="Hybrid"> <security mode="None" /> </binding> </netTcpRelayBinding> </bindings> <behaviors> <endpointBehaviors> <behavior name="CardSpaceBehavior"> <transportClientEndpointBehavior credentialType="CardSpace"> <clientCredentials> <userNamePassword userName="SoftnetSolutionsServiceBus" password="9j!Ns$R8%7" /> <federationViaCardSpace> <issuer address="http://idp.sts.microsoft.com" /> <claimTypeRequirements> <add claimType=http://schemas.xmlsoap.org/claims/Group isOptional="false" /> </claimTypeRequirements> </federationViaCardSpace> </clientCredentials> </transportClientEndpointBehavior> . SoftnetSolutions.RelayService.ShapeController The Draw Shape Controller is another part of this system. The responsibility of this Windows- based application is to select a drawing shape type and publish a message with the type. using System.Data; using System.Drawing; using System.Linq; using System.Text; using System .Windows. Forms; using System.ServiceModel; using Microsoft.ServiceBus; namespace SoftnetSolutions.RelayService.ShapeController

Ngày đăng: 05/07/2014, 01:20

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN