Showing posts with label Windows Azure Biztalk Services. Show all posts
Showing posts with label Windows Azure Biztalk Services. Show all posts

Tuesday, 24 May 2016

Angular - Azure VM Explorer and Dashboard




Azure VM Explorer

Introduction

This application allow to explore Virtual machine of your azure subscription. The application is using Azure active directory to authenticate user.
This sample demonstrates:

  • ·         The use of ADAL for JavaScript for securing an AngularJS based application.
  • ·         The use of Azure REST API for fetching subscription information.
  • ·         Perform operation on Azure VM’s .

Technology Used


  • ·         Angular JS
  • ·         Azure Subscription
  • ·         azure-active directory-library-for-js: Active Directory Authentication Library for JavaScript (ADAL JS) helps you to use Azure AD for handling authentication in your applications . Refer


Step By Step:

Step 1: Register the sample with your Azure Active Directory tenant

  1. Sign in to the Azure management portal.
  2. Click on Active Directory in the left hand nav.
  3. Click the directory tenant where you wish to register the sample application.
  4. Click the Applications tab.
  5. In the drawer, click Add.
  6. Click "Add an application my organization is developing".
  7. Enter a friendly name for the application, for example "Azure VM Explorer app", select "Web Application and/or Web API", and click next.
  8. For the sign-on URL, enter the base URL for the sample, which is by default https://localhost:44326/.
  9. For the App ID URI, enter https ://<your_tenant_name>/ Azure VM Explorer app, replacing <your_tenant_name> with the name of your Azure AD tenant.
All done! Before moving on to the next step, you need to find the Client ID of your application.
  1. While still in the Azure portal, click the Configure tab of your application.
  2. Find the Client ID value and copy it to the clipboard.

Step 2: Enable the OAuth2 implicit grant for your application

By default, applications provisioned in Azure AD are not enabled to use the OAuth2 implicit grant. In order to run this sample, you need to explicitly opt in.
  1. From the former steps, your browser should still be on the Azure management portal - and specifically, displaying the Configure tab of your application's entry.
  2. Using the Manage Manifest button in the drawer, download the manifest file for the application and save it to disk.
  3. Open the manifest file with a text editor. Search for the oauth2AllowImplicitFlow property. You will find that it is set to false; change it to true and save the file.
  4. Using the Manage Manifest button, upload the updated manifest file. Save the configuration of the app.

Step 3: Create angular JS application for Azure Virtual Machine explore

Include references to angular.js libraries, adal.js, adal-angular.js in your main app page.
Include a reference to adal module
angular.module('AzureApp', ['ngRoute','AdalAngular'])

Step 4: Initialize adal with the AAD Client Id and Tenant id .


adalProvider.init({
        instance: 'https://login.microsoftonline.com/',
        tenant: < Your Tenant Id: XXXXXXXXXXXXhotmail.onmicrosoft.com > ',
        clientId: 'Your Client Id : XXXXXXX-XXXXXXXXX,
        extraQueryParameter: 'nux=1',
        loginResource: 'https://management.azure.com/' //to set AUDIENCE
            //cacheLocation: 'localStorage', // enable this for IE, as sessionStorage does not work for localhost.
    },
    $httpProvider
);

Step 5: Create MasterController for your Angular application


'use strict';
angular.module('AzureApp').controller('MasterController', ['$scope', 'adalAuthenticationService', '$location', function($scope, adalService, $location) {
    var subscriptionId = ‘Azure Subscription Id ';
    $scope.ErrorMessage = '';
    $scope.VMList = [];
    $scope.login = function() {
        adalService.login();
        $scope.$apply();
    };
    $scope.logout = function() {
        adalService.logOut();
        $scope.$apply();
    };
    $scope.ListAllVM = function() {
        $scope.VMList = [];
        var resource = adalService.getResourceForEndpoint('https://management.azure.com/');
        var tokenStored = adalService.getCachedToken(resource);
        $.ajax({
            url: 'https://management.azure.com/subscriptions/' + subscriptionId + '/resources?api-version=2015-11-01',
            type: 'GET',
            success: function(data) {
                // $scope.VMList = data.value;
                $scope.$apply(function() {
                    angular.forEach(data.value, function(value) {
                        if (value.type == 'Microsoft.ClassicCompute/virtualMachines') {
                            //$scope.VMList.push(value);
                            $scope.GetVMInfo(value);
                        }
                    });
                });
                //do something to data
            },
            beforeSend: function(xhr) {
                xhr.setRequestHeader('Authorization', "Bearer " + tokenStored);
            },
            error: function(rcvData) {
                $scope.$apply(function() {
                    console.log(rcvData.responseText);
                    $scope.ErrorMessage = eval("(" + rcvData.responseText + ")");
                    console.log($scope.ErrorMessage.error.message)
                });
            }
        });
    };
    $scope.VMOperation = function(vm, Operation) {
        console.log(vm);
        var resource = adalService.getResourceForEndpoint('https://management.azure.com/');
        //var tokenStored = authService.getCachedToken(resource);
        var tokenStored = adalService.getCachedToken(resource);
        var _URL = 'https://management.azure.com/' + vm.id + '/' + Operation + '?api-version=2016-04-01';
        var _TYPE = 'POST';
        if (Operation == 'Delete') {
            var _URL = 'https://management.azure.com/' + vm.id + '?api-version=2016-04-01';
            var _TYPE = 'DELETE';
        } else {
            var _URL = 'https://management.azure.com/' + vm.id + '/' + Operation + '?api-version=2016-04-01';
            var _TYPE = 'POST';
        }
        $.ajax({
            url: _URL,
            type: _TYPE,
            beforeSend: function(xhr) {
                xhr.setRequestHeader('Authorization', "Bearer " + tokenStored);
            },
            error: function(rcvData) {
                $scope.$apply(function() {
                    console.log(rcvData.responseText);
                    $scope.ErrorMessage = eval("(" + rcvData.responseText + ")");
                    console.log($scope.ErrorMessage.message)
                });
            },
            success: function(data) {
                $scope.$apply(function() {
                    $scope.ErrorMessage = 'VM Operation Success';
                });
            }
        });
    };
    // Get VM Information
    //START
    $scope.GetVMInfo = function(vm) {
        var resource = adalService.getResourceForEndpoint('https://management.azure.com/');
        //var tokenStored = authService.getCachedToken(resource);
        var tokenStored = adalService.getCachedToken(resource);
        var _URL = 'https://management.azure.com/' + vm.id + '?api-version=2016-04-01';
        var _TYPE = 'GET';
        $.ajax({
            url: _URL,
            type: _TYPE,
            beforeSend: function(xhr) {
                xhr.setRequestHeader('Authorization', "Bearer " + tokenStored);
            },
            error: function(rcvData) {
                $scope.$apply(function() {
                    console.log(rcvData.responseText);
                    $scope.ErrorMessage = eval("(" + rcvData.responseText + ")");
                    console.log($scope.ErrorMessage.error.message)
                });
            },
            success: function(data) {
                $scope.$apply(function() {
                    vm.status = data.properties.instanceView.status;
                    $scope.VMList.push(vm);
                });
            }
        });
    };
}]);

Step 6: Create View for your Angular App.


 






<div ng-init="ListAllVM()">
    <div class="alert alert-danger" ng-show="ErrorMessage">
                                {{ErrorMessage.message}}
                                                                                                                                {{ErrorMessage.error.message}}
</div>
    <div class="panel">
        <table class="table table-striped table-bordered table-hover">
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Location</th>
                    <th>Status</th>
                </tr>
            </thead>
            <tbody>
                <tr data-ng-repeat="item in VMList">
                    <td>
                        <a href="#" ng-click="GetVMInfo(item)">
                            <p> {{item.name}}</p>
                            <a/>
                        </td>
                        <td>
                            <p> {{item.location}}</p>
                        </td>
                        <td>
                            <p> {{item.status}}</p>
                        </td>
                        <td>
                            <a href="#/VMList" ng-disabled="{{item.status != 'StoppedDeallocated'}}" class="form-control">
                                <i class="fa fa-play fa-fw" ng-click="VMOperation(item,'start')"></i>
                            </a>
                        </td>
                        <td>
                            <a href="#/VMList" ng-disabled="{{item.status != 'ReadyRole'}}" ng-click="VMOperation(item,'powerOff')" class="form-control">
                                <i class="fa fa-stop fa-fw"></i>
                                <a/>
                            </td>
                            <td>
                                <a href="#/VMList" ng-disabled="" ng-click="VMOperation(item,'restart')" class="form-control">
                                    <i class="fa fa-refresh fa-fw"></i>
                                    <a/>
                                </td>
                                <td>
                                    <a href="#/VMList" ng-disabled="" ng-click="VMOperation(item,'deallocate')" class="form-control">
                                        <i class="fa fa-stop fa-fw"></i>(Deallocate)
                                        <a/>
                                    </td>
                                    <td>
                                        <a href="#/VMList" ng-click="VMOperation(item,'Delete')" class="form-control">
                                            <i class="fa fa-remove fa-fw"></i>
                                            <a/>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>

Code

Please download source code from location .


Thursday, 20 February 2014

How to integrate Two way WCF Service with Windows Azure Biztalk Services


Introduction

This sample demonstrates how to integrate web application running on-premises or in the cloud with two ways WCF Service, via Windows Azure BizTalk Services.
 

Architecture


The following diagram shows the architecture of the solution.


 








Prerequisites

  • Visual Studio 2012 Express for Windows 8
  • Windows Azure Biztalk Services SDK for Windows 8
  • and a Windows Azure account (get the Free Trial)
 


Step by Step 



Create WCF Service and Host it on cloud.


Create a Windows Azure Cloud Service Project.
















Add WCFServiceWebRole
 














Change The Iservice class to IVendorInventoryService

 











Change the code for VendorInventoryService










Create the Package to deploy on Cloud




























Deploy package on Cloud.
Log on to cloud portal.
Click on New Cloud Service.
















Enter the name of Service
 
















Select the package and configuration from local


















Click the “Deploy even if one or more roles contain a single instance”.


 














You can check in IE that service in hosted properly.
 
















Test the WCF  service using SOAP UI.















Create The Biztalk Services.


Create the Biztalk Service project.

 














Create Input Schema for receive request from web / HTML Application.
 














Add another XML Schema Inventory Response

 














Create XML Structure for InventoryResponse.
 















Generate Schema for Service using add Schemas from service Wizard.
 





















Enter the end point of service .
 




















Click on Get and Import , to include schema into solution.
 

















Create Map for convert Inventory Request to Inventory Service Request.

 














Create Map for Inventory Service Response to InventoryResponse



































Configure XML RequestReplyBridge.
Configure Message Type of Request and Response of Bridge.
 












Configure Map for Request Message.















Configure Map for Response Message
 

































Set the runtime address of Two Way External Service

 








Set the filter condition of link
 














Set action
 















Set the Biztalk Service URL of MessageFlowIternary.


 








Deploy the solution. 
















You can check the application deployed properly by checking on portal resources.

 













Test The Solution.

Send Message to Bridge using Biztalk Services Explorer.
 






















Load the Sample Instance and Send the request.
 














Possible Error

The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver.  Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).


Solution: if you have not add proper Action in Soap action then this Error will come, you can check the action from wsdl of service