Git Product home page Git Product logo

servicefabric.wcfcalc's Introduction

ServiceFabric.WcfCalc

Service Fabric Stateless Service hosting a publicly accessible (Web HTTP) WCF service.

What

This code sample shows how you can run WCF services in Stateless Services on Azure Service Fabric.

Use the overload of the constructor of WcfCommunicationListener that takes 'address' instead of 'endpointResourceName', so you can influence on what URL the WCF service will be listening.

How to create a WCF Service with a WebHttpBinding (REST):

  string host = context.NodeContext.IPAddressOrFQDN;
  var endpointConfig = context.CodePackageActivationContext.GetEndpoint("CalculatorEndpoint");
  int port = endpointConfig.Port;
  string scheme = endpointConfig.Protocol.ToString();
  string uri = string.Format(CultureInfo.InvariantCulture, "{0}://{1}:{2}/", scheme, host, port);
  var listener = new WcfCommunicationListener<ICalculatorService>(
    serviceContext: context,
    wcfServiceObject: new WcfCalculatorService(),
    listenerBinding: new WebHttpBinding(WebHttpSecurityMode.None),
    address: new EndpointAddress(uri)
  );
  var ep = listener.ServiceHost.Description.Endpoints.Last();
  ep.Behaviors.Add(new WebHttpBehavior());
  return listener;

How to create a WCF Service with a BasicHttpBinding (SOAP):

  string host = context.NodeContext.IPAddressOrFQDN;
  var endpointConfig = context.CodePackageActivationContext.GetEndpoint("CalculatorEndpoint");
  int port = endpointConfig.Port;
  string scheme = endpointConfig.Protocol.ToString();
  string uri = string.Format(CultureInfo.InvariantCulture, "{0}://{1}:{2}/", scheme, host, port);
  var listener = new WcfCommunicationListener<ICalculatorService>(
    serviceContext: context,
    wcfServiceObject: new WcfCalculatorService(),
    listenerBinding: new BasicHttpBinding(BasicHttpSecurityMode.None),
    address: new EndpointAddress(uri)
  );

  // (Optional) Check to see if the service host already has a ServiceMetadataBehavior
  ServiceMetadataBehavior smb = listener.ServiceHost.Description.Behaviors.Find<ServiceMetadataBehavior>();
  if (smb == null)
  {
    smb = new ServiceMetadataBehavior();
    smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
    smb.HttpGetEnabled = true;
    smb.HttpGetUrl = new Uri(uri);
    listener.ServiceHost.Description.Behaviors.Add(smb);
}
return listener;

Configuration

The line

context.CodePackageActivationContext.GetEndpoint("CalculatorEndpoint")

reads its data from the file 'ServiceManifest.xml' Make sure the port mentioned here matches a rule in the load balancer.

<Resources>
    <Endpoints>
      <!-- This endpoint is used by the communication listener to obtain the port on which to 
           listen. Please note that if your service is partitioned, this port is shared with 
           replicas of different partitions that are placed in your code. -->
      <Endpoint Name="CalculatorEndpoint" Protocol="http" Type="Input" Port="80" />
    </Endpoints>
  </Resources>

servicefabric.wcfcalc's People

Contributors

loekd avatar

Watchers

James Cloos avatar Wayne Munro avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.