Question

bgarr33434 on Sat, 26 Nov 2016 15:36:58


Running a web app, built on VS15, endpoint is http://alexaintentvm.azurewebsites.net:50000/

listener.Prefixes.Add(MyEndpoint);
            listener.Start(); //always fails here because (I believe) I need elevated (admin) permissions to open a port, or be able to run netsh http add urlacl http://alexaintentvm.azurewebsites.net:50000/ user=<brian@cognitivecode.com>


Sponsored



Replies

Sadiqh Ahmed on Sun, 27 Nov 2016 10:24:35


Hi,

Thank you for posting here!

Web Apps are restricted to ports 80/443 for inbound requests. However, there is no restriction on Outbound IP addresses and ports.

Out of the box, Azure Web Apps will only allow you to put restrictions on incoming requests using DIPR http://azure.microsoft.com/blog/2013/12/09/ip-and-domain-restrictions-for-windows-azure-web-sites/. There is no mechanism to restrict Outbound.

See this reference: https://social.msdn.microsoft.com/Forums/en-US/c9bcfc43-b962-47ef-a856-36bf5f9e9bdd/open-ports-for-web-apps?forum=windowsazurewebsitespreview

If you want to add trace listener using VS, refer this link - https://docs.microsoft.com/en-in/azure/app-service-web/web-sites-dotnet-troubleshoot-visual-studio

Hope that helps!

Best Regards

Sadiqh Ahmed
________________________________________________________________________________________________

bgarr33434 on Sun, 27 Nov 2016 16:56:24


Unfortunately, after 3 days, I still can't connect to the app service.  I'm submitting the js running out of AWS Lambda.  Why can't Azure show me the connection attempt and what is failing?  i'm just guessing in the dark!

// Javacript for proxying intent

var http = require('http');

var MyApplicationId = "amzn1.ask.skill.a15efd21-ff4f-4fe0-93c6-5a593390ea38"; // change to your ApplicationId
var MyEndpoint = "http://alexaintent.azurewebsites.net"; // change to your Endpont

/**
 * This sample demonstrates a simple skill built with the Amazon Alexa Skills Kit.
 * For additional samples, visit the Alexa Skills Kit developer documentation at
 * https://developer.amazon.com/appsandservices/solutions/alexa/alexa-skills-kit/getting-started-guide
 */

// Route the incoming request based on type (LaunchRequest, IntentRequest,
// etc.) The JSON body of the request is provided in the event parameter.
exports.handler = function (event, context) {
    try {
        console.log("event=" + JSON.stringify(event));

        /**
         * Uncomment this if statement and populate with your skill's application ID to
         * prevent someone else from configuring a skill that sends requests to this function.
         */

        if (event.session.application.applicationId === MyApplicationId)
            ; // from Echo
        else if (event.session.application.applicationId === "amzn1.ask.skill.a15efd21-ff4f-4fe0-93c6-5a593390ea38")
                ; // from Amazon Lambda Test ... or intruder
        else
            context.fail("Invalid Application ID");

        console.log("new:" + event.session.new);
        if (event.session.new) {
            onSessionStarted({ requestId: event.request.requestId }, event.session, function callback(sessionAttributes, speechletResponse) {
                console.log("new: speechletResponse:" + speechletResponse);
            });
        }

        console.log("type:" + event.request.type);
        if (event.request.type === "LaunchRequest") {
            onLaunch(event.request,
                     event.session,
                     function callback(sessionAttributes, speechletResponse) {
                         context.succeed(buildResponse(sessionAttributes, speechletResponse));
                     });
        } else if (event.request.type === "IntentRequest") {
            onIntent(event.request,
                     event.session,
                     function callback(sessionAttributes, speechletResponse) {
                         context.succeed(buildResponse(sessionAttributes, speechletResponse));
                     });
        } else if (event.request.type === "SessionEndedRequest") {
            onSessionEnded(event.request, event.session, function callback(sessionAttributes, speechletResponse) {
                console.log("SessionEndedRequest: speechletResponse:" + speechletResponse);
                context.succeed();
            });
            //context.succeed(); // I don't believe it is correct to have context.succeed() here. It prevents OnSessionEnded() from being raised.
        } else
            context.fail("Exception: unknown event.request.type");
    } catch (e) {
        context.fail("Exception: " + e);
    }
};

/**
 * Called when the session starts.
 */
function onSessionStarted(sessionStartedRequest, session, callback) {
    console.log("onSessionStarted requestId=" + sessionStartedRequest.requestId
                + ", sessionId=" + session.sessionId);

    // Dispatch to your skill's Start.
    var jsonStartedRequest = JSON.stringify(sessionStartedRequest);
    var jsonSession = JSON.stringify(session);
    var url = MyEndpoint + "/start?request=" + escape(jsonStartedRequest) + "&session=" + escape(jsonSession);
    httpCallAsync(url, callback);
}

/**
 * Called when the session ends.
 */
function onSessionEnded(sessionEndedRequest, session, callback) {
    console.log("onSessionEnded requestId=" + sessionEndedRequest.requestId
                + ", sessionId=" + session.sessionId);

    // Dispatch to your skill's End.
    var jsonEndedRequest = JSON.stringify(sessionEndedRequest);
    var jsonSession = JSON.stringify(session);
    var url = MyEndpoint + "/end?request=" + escape(jsonEndedRequest) + "&session=" + escape(jsonSession);
    httpCallAsync(url, callback);
}

/**
 * Called when the user launches the skill without specifying what they want.
 */
function onLaunch(launchRequest, session, callback) {
    console.log("onLaunch requestId=" + launchRequest.requestId
                + ", sessionId=" + session.sessionId);

    // Dispatch to your skill's Launch.
    var jsonLaunchRequest = JSON.stringify(launchRequest);
    var jsonSession = JSON.stringify(session);
    var url = MyEndpoint + "/launch?request=" + escape(jsonLaunchRequest) + "&session=" + escape(jsonSession);
    httpCallAsync(url, callback);
}

/**
 * Called when the user specifies an intent for this skill.
 */
function onIntent(intentRequest, session, callback) {
    console.log("Called onIntent intent=" + intentRequest.intent
                + ", intentName=" + intentRequest.intent.name);

    // Dispatch to your skill's Intent.
    var jsonIntentRequest = JSON.stringify(intentRequest);
    var jsonSession = JSON.stringify(session);
    var url = MyEndpoint + "/intent?request=" + escape(jsonIntentRequest) + "&session=" + escape(jsonSession);
    httpCallAsync(url, callback);
}

function httpCallAsync(url, callback) {
    console.log("httpCall: url=" + url);

    console.log("httpCall: before http.get:" + url);
    http.get(url, function (res) {
        console.log("httpCall: after http.get:" + res.on);
        var responseString = '';

        res.on('data', function (data) {
            console.log("httpCall: entered data on");
            responseString += data;
            console.log("httpCall: exited data on");
        })

        res.on('error', function (e) {
            console.log("httpCall: Got error: " + e.message);
        })

        res.on('end', function () {
            console.log("httpCall: entered end on");
            if (callback !== undefined) {
                var repromptText = "";

                var cardTitle = "Alexa HA Request";
                var sessionAttributes = {};

                console.log("httpCall: before parse: responseString:" + responseString);
                var response = JSON.parse(responseString);
                console.log("httpCall: after parse: response:" + response);
                var speechOutput = response.text;
                var shouldEndSession = response.shouldEndSession;

                console.log("httpCall: before callback: sessionAttributes:" + sessionAttributes + " cardTitle:" + cardTitle + " speechOutput:" + speechOutput + " repromptText:" + repromptText + " shouldEndSession:" + shouldEndSession);
                callback(sessionAttributes,
                 buildSpeechletResponse(cardTitle, speechOutput, repromptText, shouldEndSession));
            }
            console.log("httpCall: exiting end on");
        })
    })
}

// --------------- Helpers that build all of the responses -----------------------

function buildSpeechletResponse(title, output, repromptText, shouldEndSession) {
    return {
        outputSpeech: {
            type: "PlainText",
            text: output
        },
        card: {
            type: "Simple",
            title: "SessionSpeechlet - " + title,
            content: "SessionSpeechlet - " + output
        },
        reprompt: {
            outputSpeech: {
                type: "PlainText",
                text: repromptText
            }
        },
        shouldEndSession: shouldEndSession
    }
}

function buildResponse(sessionAttributes, speechletResponse) {
    return {
        version: "1.0",
        sessionAttributes: sessionAttributes,
        response: speechletResponse
    }
}

Jeff Sanders on Tue, 13 Dec 2016 13:13:13


Hi Brian,

For Azure App Services you can only listen on 80 and 443.  If you move to an Azure VM or Azure Cloud Services you can listen on other ports.

-Jeff