How it works...

Before we can run the client application, however, we need to publish our service first. In Solution Explorer, right-click on the sfApp service and click on Publish... from the context menu:

The Publish Service Fabric Application window will now be displayed. Click on the Select... button next to the Connection Endpoint textbox. Select Local Cluster as your Connection Endpoint and click on OK. Change Target profile and Application Parameters File to Local.1Node.xml. When you are done, click on the Publish button:

If you navigate to http://localhost:19080/Explorer, you will notice that the service you created has been published to your local Service Fabric cluster:

You are now ready to run your client application. Right-click on the sfApp.Client project and select Debug and Start new instance from the context menu. The console application calls the validate method to check the e-mail addresses and displays the results to the console window. The results are as expected:

If you receive a System.BadImageFormatException when trying to run your console application, check to see what platform your console application is targeting. You might have compiled your console application as Any CPU while the other projects in your solution target x64. Modify this from the Configuration Manager and make the console application also target x64.

We can, however, be more specific when creating the actor ID. In the previous code listing, we used the CreateRandom() method to generate an ActorId. We can now give it a specific name. Modify your proxy code and create a new ActorId instance and give it any string value. In the following code listing, I just called mine Utilities:

var actProxy = ActorProxy.Create<IUtilitiesActor>(new ActorId("Utilities"), "fabric:/sfApp");
The ActorId method can take a parameter of type Guid, long, or string.

When you debug your client application again, you will notice that Utilities Actor now has a logical name (the same name you passed as string value when creating a new ActorId instance):

Creating your Service Fabric application and publishing it locally is a perfect solution for testing your application before publishing it to the cloud. Creating small, independent microservices allows developers many benefits related to testing, debugging, and deploying efficient and robust code that your applications can leverage to ensure maximum availability.

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

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