Web service deployment

The web service implementation is currently ready. Thus, you need to deploy it to be able to connect to it from the game, and obtain the results, for example, about the ranks. The deployment can be made in a few ways, for example, on a local development machine or in the external hosting environment (either dedicated or shared), as shown in the following diagram. In this book, only the option of a local deployment is presented.

Web service deployment

Development deployment

The local deployment makes it possible to test the web service, and perform modifications locally. It is especially useful while developing the web service, because you can easily introduce new features, debug them, and test them without the necessity of deploying a new version of the service on an external web server. Thus, if many versions of the service are created, you can work in a more comfortable way.

You can connect to the web service that is deployed locally, either from the emulator or from the phone. In the latter case, you need to use the WiFi connection to a local network to be able to access the web service via the internal IP address, such as 192.168.0.2.

IIS Express hosting

The web service will be hosted by IIS Express. To start it, you need to choose the Debug and Start Debugging or Start Without Debugging options in the IDE. You can also click on the button with a green triangle available in the menu. If the Internet Explorer option is chosen as the target (and the project node is selected in Solution Explorer), the browser is started, and a list of files is presented. The new icon (representing IIS Express) should also be added to the taskbar.

Access by IP address

Currently, you are not able to connect to the web service even from the emulator. Its architecture causes it to be recognized as an additional network device. Therefore, you cannot use the localhost name to connect to the web service. To solve this problem, you need to allow the access to the web service by a particular IP address.

At the beginning, you should get your current local IP address by using of the ipconfig command. To do this, open the command prompt, by pressing the Windows key + the R key, typing cmd, and confirming with Enter. Then, run the ipconfig command. You should receive the information about various network cards, and you need to select a suitable network card with an assigned IP address. In the following example, the IP address is 192.168.0.2:

Ethernet adapter (...):
   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : (...)
   IPv4 Address. . . . . . . . . . . : 192.168.0.2
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.0.1

Next, open the My documents, IISExpress, and config directories. Here, you should open the applicationhost.config file in Notepad. Then, search for the site node with the value of the name attribute equal to SpaceAim3D.WebService. You should add a new binding node and replace the localhost value with the IP address (for example, 192.168.0.2), similar to the following example. It is worth mentioning that the port number is specified together with the IP address in the bindingInformation attribute. You should remember it, because it will be necessary later.

<site name="SpaceAim3D.WebService" id="3"> 
(...)
  <bindings>
    <binding protocol="http" 
      bindingInformation="*:1217:localhost" />
    <binding protocol="http" 
      bindingInformation="*:1217:192.168.0.2" />
  </bindings>
</site>

At the end, close the IDE and run it once again, but with the administrator privileges. This is important, because launching without the administrative privileges will not make it possible to access the web service by the IP address.

To be able to connect to the web service from the emulator and the phone, you also need to add a new rule in the Windows Firewall. At the beginning, you should open the firewall advanced settings. To do this, open Control Panel, navigate to the System and Security group, select Windows Firewall, and click on Advanced settings (on the left). Then, choose the Inbound Rules option, and click on the New Rule item (on the right). It starts the wizard where you specify settings of a new rule. Its type is port, the protocol is TCP, the port number is 1217 (or other, as in the web service address), and the action is allow the connection.

The rule should be applied only to the private networks (or other types, depending on the type of the network that you have configured), and its name can be set to Space Aim 3D Development. At the end, click on the Finish button.

While running the game, the rule should be active. However, you can easily disable it by choosing the Disable Rule option from the context menu of the item in the Inbound Rules section of the Windows Firewall with Advanced Security window. You can even delete the rule by choosing the Delete option.

Web service testing

The IDE makes it possible to open a special tool for testing the web service. It allows you to invoke particular methods and pass various parameter values. Thus, you can add some data into the database and test particular operations. To start WCF Test Client, you should select the SA3DService.svc file in Solution Explorer and press F5 or choose a suitable option from the Debug menu.

The program window consists of two parts, as shown in the following screenshot:

Web service testing

On the left, there is a tree with the service project, including the ISA3DService interface representing your web service. Its child nodes indicate particular operations supported by the service. On the right, the main workspace is available. It can contain many tabs related to particular operations performed on the web service. Here, you can specify the request parameters, invoke the method (by clicking on the Invoke button), and see a response, in both the formatted and the plain XML format.

You have already finished the web service local deployment, and you should be able to connect to it from the emulator as well as the phone. However you should not close Microsoft Visual Studio Express 2012 for Web, to be able to access the web service while consuming it by the Space Aim 3D game. You can easily check whether IIS Express is running by verifying that its icon is visible in the taskbar.

Production deployment

This book does not cover the process of the web service deployment on the external web server or in the cloud. In such scenarios, some modifications can be required, for example, it could be necessary to move the local database to the dedicated SQL Server, and perform some modifications in the web service project.

The important file, from the perspective of the web service deployment, is Web.config. Here, you can specify the connection string (the connectionStrings node), which describes how you can connect to the database. You can also disable disclosing the metadata and the exception information by setting the suitable values in the serviceMetadata and serviceDebug nodes, inside the behavior node.

Some other modifications are related to security settings. You can configure various levels of security to adjust the web service to your needs.

Tip

It is important to test the web service both before and after the production deployment, to be certain that it works according to your assumptions, and does not return incorrect result or cause any security problems.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.158.165