Is an external HTTP endpoint possible as an Azure employee?

I am trying to host an external WCF service on Azure inside a production role.

I have a solution that works very nicely locally, but when I try to publish it to Azure, it goes into the initialization / busy / stop cycle.

The information I found on the Internet says different things:

http://www.theworkflowelement.com/2011/01/worker-role-service-hosting-faq.html (not possible)

http://code.msdn.microsoft.com/WCF-Azure-Worker-Role-on-b394df49 (possibly with hacking)

Other sources say this is possible, but I do not have a representative to publish more than two links.

The latter, when I try to publish it, freezes.

Does anyone know how to do this, or if it is really impossible? It would be very convenient to place it in the role of a worker, so I do not need to use svc and web.config mess, which entail a web role.

This is the code I'm using:

[ServiceContract(Namespace = "")] public interface IMyService { [OperationContract] [WebGet] string Echo(string s); } public class MyService : IMyService { public string Echo(string s) { return "hey " + s; } } public class TestPasswordValidator : UserNamePasswordValidator { public override void Validate(string userName, string password) { } } private static void StartService() { var endpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["HttpsEndpoint"]; var uri = new Uri(endpoint.Protocol + "://" + endpoint.IPEndpoint + "/myservice"); var host = new ServiceHost(typeof(MyService), uri); host.Credentials.UserNameAuthentication.UserNamePasswordValidationMode = UserNamePasswordValidationMode.Custom; host.Credentials.UserNameAuthentication.CustomUserNamePasswordValidator = new TestPasswordValidator(); var mexBehavior = new ServiceMetadataBehavior(); mexBehavior.HttpsGetEnabled = true; mexBehavior.MetadataExporter.PolicyVersion = PolicyVersion.Policy15; host.Description.Behaviors.Add(mexBehavior); var soapBinding = new WSHttpBinding(SecurityMode.TransportWithMessageCredential); soapBinding.Security.Message.ClientCredentialType = MessageCredentialType.UserName; host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpsBinding(), "mex"); host.AddServiceEndpoint(typeof(IMyService), soapBinding, "Soap"); var restBinding = new WebHttpBinding(WebHttpSecurityMode.Transport); restBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; var restEndpoint = host.AddServiceEndpoint(typeof(IMyService), restBinding, ""); restEndpoint.Behaviors.Add(new WebHttpBehavior { HelpEnabled = true, DefaultOutgoingResponseFormat = WebMessageFormat.Json, AutomaticFormatSelectionEnabled = true, DefaultBodyStyle = WebMessageBodyStyle.WrappedRequest }); host.Open(); } public override void Run() { StartService(); while (true) { Thread.Sleep(10000); } } public override bool OnStart() { // Set the maximum number of concurrent connections ServicePointManager.DefaultConnectionLimit = 12; // For information on handling configuration changes // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357. return base.OnStart(); } 
+4
source share
2 answers

I understood why this is happening. Worker roles must be run with elevated permissions to open HTTP ports. However, this option is not available in the gui role settings. The gui setup shows that I thought that controls permissions is Full trust / Partial trust. I guess I have no idea what this does.

The correct configuration is in the ServiceDefinition.csdef file under WorkerRole.

 <Runtime executionContext="elevated" /> 
+10
source

This is entirely possible (I have done this several times), and most likely the busy / init loop has nothing to do with solving your architecture.

If you don't mind, can you share the start / start code for your working role? Not a service, just part of a ServiceHost. Also, do you use any third-party libraries in your service, etc.?

0
source

Source: https://habr.com/ru/post/1341631/


All Articles