<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Sujit's .NET and Windows Ramblings</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/sujitdmello/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/sujitdmello/feed.xml</link>
    <description>Thoughts and experiences from an avid .NET developer</description>
    <lastBuildDate>Tue, 16 Apr 2019 05:31:11 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Thoughts on Microservices</title>
      <link>https://docs.microsoft.com/archive/blogs/sujitdmello/thoughts-on-microservices</link>
      <pubDate>Wed, 24 Feb 2016 06:24:00 GMT</pubDate>
      <dc:creator><![CDATA[Sujit DMello]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sujitdmello/2016/02/24/thoughts-on-microservices/</guid>
      <description><![CDATA[Based on various readings/research I've done recently, I decided to summarize my understanding of...]]></description>
      <content:encoded><![CDATA[<div><span style="font-family: Calibri; font-size: small;">Based on various readings/research I've done recently, I decided to summarize my understanding of Microservices. For the most part, this is platform-neutral:</span></div>
<ul>
<li><span style="font-family: Calibri; font-size: small;">Microservices can be considered &lsquo;fine-grained SOA&rsquo; &ndash; a small self-contained service that does not depend on other microservices.</span></li>
<li><span style="font-family: Calibri; font-size: small;">These services are mostly composed and orchestrated together to form more complex application services.</span></li>
<li><span style="font-family: Calibri; font-size: small;">Typically small feature-focused teams will create these microservices.</span></li>
<li><span style="font-family: Calibri; font-size: small;">Each team is free to use any technology/stack that makes them productive. Each microservice can use different versions of frameworks/platforms.</span></li>
<li><span style="font-family: Calibri; font-size: small;">DevOps mentality means each team is also responsible for deploying the microservice into production and monitoring and managing it.</span></li>
<li><span style="font-family: Calibri; font-size: small;">Have a self-service capability that allows teams to &lsquo;spin-up&rsquo; a service to test/develop ideas. (this is where the private Paas/cloud helps).</span></li>
<li><span style="font-family: Calibri; font-size: small;">Organization structure should be built around this idea of microservices &ndash; it should not be some huge team but a number of small independent teams.</span></li>
<li><span style="font-family: Calibri; font-size: small;">Once a service is out there, it never goes away. You can put new versions side-by-side and redirect calls to the new version, but the old version remains around. If there is an issue with the new version, traffic is routed back to the old version (automatically or manually).</span></li>
<li><span style="font-family: Calibri; font-size: small;">Microservices are cornerstone of the system so they should be very, very, very well tested. Try to break it before publishing it to production.</span></li>
<li><span style="font-family: Calibri; font-size: small;">All deployment, management is done through script &hellip; no manual process.</span></li>
<li><span style="font-family: Calibri; font-size: small;">De-normalize all data so that it can be sharded as much as possible.</span></li>
<li><span style="font-family: Calibri; font-size: small;">P</span><span style="font-family: Calibri; font-size: small;">referably these services&nbsp;should be stateless but this can be tricky. <a title="Azure Service Fabric" href="https://azure.microsoft.com/en-us/services/service-fabric/">Azure Service Fabric </a>allows you to build statefull microservices with no downside.</span></li>
<li><span style="font-family: Calibri; font-size: small;">Every service should have a client access library &ndash; do not require apps to call your service via REST endpoint as different interpretations of the methods etc. may cause confusion.</span></li>
<li><span style="font-family: Calibri; font-size: small;">Because microservices get called so often, consider using a binary format like Google Protocol Buffer, instead of JSON. This will reduce network congestion and improve performance.</span></li>
<li><span style="font-family: Calibri; font-size: small;">Tooling is the secret sauce that makes microservices viable in the enterprise. There are some open source tools but you will have to build many of your own because:</span>
<ul>
<li><span style="font-family: Calibri; font-size: small;">Microservices are complex to build and compose.</span></li>
<li><span style="font-family: Calibri; font-size: small;">Avoid duplicate code everywhere.</span></li>
<li><span style="font-family: Calibri; font-size: small;">Versioning is not easy.</span></li>
<li><span style="font-family: Calibri; font-size: small;">Same with routing.</span></li>
<li><span style="font-family: Calibri; font-size: small;">Common interface naming requires some sort of repository.</span></li>
<li><span style="font-family: Calibri; font-size: small;">Monitoring and logging should be inherent (not a separate microservice).</span></li>
</ul>
</li>
<li><span style="font-family: Calibri; font-size: small;">A good PaaS system makes some of these issues go away and adds autoscaling, service discovery, versioning, rollback, fault tolerance etc.</span></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>WsdlExporter.GetGeneratedMetadata is called once and only once</title>
      <link>https://docs.microsoft.com/archive/blogs/sujitdmello/wsdlexporter-getgeneratedmetadata-is-called-once-and-only-once</link>
      <pubDate>Tue, 29 Sep 2015 10:33:00 GMT</pubDate>
      <dc:creator><![CDATA[Sujit DMello]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sujitdmello/2015/09/29/wsdlexporter-getgeneratedmetadata-is-called-once-and-only-once/</guid>
      <description><![CDATA[If you have to provide a custom WSDL as part of your WCF service, you have to extend the...]]></description>
      <content:encoded><![CDATA[<p>If you have to provide a custom WSDL as part of your WCF service, you have to extend the <a href="https://msdn.microsoft.com/en-us/library/system.servicemodel.description.wsdlexporter(v=vs.110).aspx">WsdlExporter</a> class and implement the <a href="https://msdn.microsoft.com/en-us/library/system.servicemodel.description.wsdlexporter.getgeneratedmetadata(v=vs.110).aspx">GetGeneratedMetadata</a> method. This method returns a <a href="https://msdn.microsoft.com/en-us/library/system.servicemodel.description.metadataset(v=vs.110).aspx">MetadataSet </a>object which encapsulates the WSDL that represents the service.&nbsp;One of the reasons you may take this route is if you want to add some custom metadata to the WSDL. The one thing to remember about this method is that WCF will call it exactly once to get the WSDL when someone first calls the ?WSDL or MEX endpoint of your&nbsp; service. If you return a valid WSDL from this method, it is cached and used on subsequent calls to the metadata endpoint. On the other hand, if for some reason, you get an exception on that first call, then WCF 'remembers' the exception and will return it on subsequent&nbsp;calls to the metadata endpoint. If you encountered a transient, recoverable error when generating the metadata, you don't get another chance to generate it. the only solution at this time is to restart the app domain.</p>
<p>This behavior is by design as the WSDL is considered a 'static' thing and must always be the same for a service, so there is no retry logic built into WCF to call it more than once in the event of an error.</p>
<p>This is the one point I wanted to get across in the post - as far as possible, avoid doing anything fancy in the <em>GetGeneratedMetadata</em> method and ensure it is always able to return a WSDL, possible read from a local file.</p>]]></content:encoded>
    </item>
    <item>
      <title>Step-by-step installation instructions for getting DNX on your Windows machine</title>
      <link>https://docs.microsoft.com/archive/blogs/sujitdmello/step-by-step-installation-instructions-for-getting-dnx-on-your-windows-machine</link>
      <pubDate>Thu, 23 Apr 2015 04:58:00 GMT</pubDate>
      <dc:creator><![CDATA[Sujit DMello]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sujitdmello/2015/04/23/step-by-step-installation-instructions-for-getting-dnx-on-your-windows-machine/</guid>
      <description><![CDATA[Steps to install DNX (.NET Execution environment)&nbsp;
The original instructions are here, but the...]]></description>
      <content:encoded><![CDATA[<p><span style="color: #993300; font-size: large;">Steps to install DNX (.NET Execution environment)&nbsp;</span></p>
<p><em>The original instructions are <a href="https://github.com/aspnet/Home/tree/dev">here</a>, but the steps below are organized better and fill some gaps. Except for the .NET 4.5.2, PowerShell 4.0 and VC++ redistributable, you don't need admin access for DNX itself as it deploys to your user folder.</em></p>
<p>Upgrade to <a href="https://www.microsoft.com/en-us/download/details.aspx?id=42643">.NET 4.5.2</a> (or higher) if you don't have it - Note needs about 3GB on C drive so you may have to make room first. This&nbsp;is a pre-requisite for PowerShell.<br /> Reboot!</p>
<p>Upgrade PowerShell to latest version (4.0) if you don't have it already<br /> &nbsp;<a href="https://www.microsoft.com/en-us/download/details.aspx?id=40855&amp;WT.mc_id=rss_alldownloads_all">https://www.microsoft.com/en-us/download/details.aspx?id=40855&amp;WT.mc_id=rss_alldownloads_all</a><br /> (Select x64 version)<br /> Reboot!</p>
<p>Install the Visual C++ 2013 redistributable package from <a href="https://www.microsoft.com/en-us/download/details.aspx?id=40784">here</a> (in case you don't have it already). Install both the x86 and x64 packages. This is pre-requisite for Kestrel (the development web server).</p>
<p>Run <strong>PowerShell</strong></p>
<p>Check powershell version:<br /> &nbsp;<strong>$PSVersionTable.PSVersion</strong> (should be 4.0)</p>
<p><strong>Exit</strong> PowerShell</p>
<p>&nbsp;</p>
<p>Issue the following command:</p>
<p><strong>@powershell -NoProfile -ExecutionPolicy unrestricted -Command "&amp;{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))}"</strong></p>
<p>This will install DNVM (.NET Version Manager) to your user folder.</p>
<p>Close command prompt window.</p>
<p>&nbsp;</p>
<p>Open new Command Prompt</p>
<p><strong>dnvm</strong></p>
<p>You should see help information for the DNVM command</p>
<p>&nbsp;</p>
<p>If you use a Proxy Server within your environment (at work for example), pay attention to the next 2 lines, otherwise skip over it.<br /> &nbsp;<strong>setx http_proxy </strong><strong><a href="https://proxy.server.com:1234">https://proxy.server.com:1234</a></strong></p>
<p>Close prompt and open a new one - check that http_proxy environment variable has been set correctly.</p>
<p>&nbsp;</p>
<p><strong>dnvm install latest -Unstable -Persistent </strong>(this will pull the latest runtime bits and install to your user folder)&nbsp;</p>
<p><strong>dnvm list </strong>(this will show you all the installed runtimes and a * will be next to the current default)</p>
<p>Close prompt and open a new one</p>
<p>Type the following command:</p>
<p><strong>dnx</strong></p>
<p>You should see help information for DNX</p>
<p>&nbsp;</p>
<p>Occasionally you can run the following command to get the latest DNX and DNVM bits:</p>
<p><strong>dnvm upgrade</strong></p>
<p><strong>dnvm update-self </strong></p>
<p><br /> Finally we need to tell the package management system to get packages from the DEV package server.</p>
<p>Update c:\users\&lt;user&gt;\AppData\Roaming\Nuget\NuGet.config (this determines which source DNU RESTORE will use) with these contents. You can merge the existing contents.</p>
<p><br /> <em>&lt;?xml version="1.0" encoding="utf-8"?&gt;<br /> &lt;configuration&gt;<br /> &nbsp; &lt;packageSources&gt;<br /> &nbsp;&nbsp;&nbsp; &lt;add key="AspNetVNext" value="</em><a href="https://www.myget.org/F/aspnetvnext/api/v2/"><em>https://www.myget.org/F/aspnetvnext/api/v2/</em></a><em>" /&gt;<br /> &nbsp;&nbsp;&nbsp; &lt;add key="nuget.org" value="</em><a href="https://www.nuget.org/api/v2/"><em>https://www.nuget.org/api/v2/</em></a><em>" /&gt;<br /> &nbsp; &lt;/packageSources&gt;<br /> &nbsp; &lt;disabledPackageSources /&gt;<br /> &nbsp; &lt;activePackageSource&gt;<br /> &nbsp;&nbsp;&nbsp; &lt;add key="AspNetVNext" value="</em><a href="https://www.myget.org/F/aspnetvnext/api/v2/"><em>https://www.myget.org/F/aspnetvnext/api/v2/</em></a><em>" /&gt;<br /> &nbsp; &lt;/activePackageSource&gt;<br /> &lt;/configuration&gt;</em></p>
<p>&nbsp;</p>
<p>Another option is&nbsp;use this DNU command instead of 'dnu restore':</p>
<p><strong>&nbsp;dnu restore -s </strong><strong><a href="https://www.myget.org/F/aspnetvnext">https://www.myget.org/F/aspnetvnext</a></strong></p>
<p>Note DNU is the .NET Utility which includes functionality to restore packages, build packages, compile code etc.</p>
<p>&nbsp;</p>
<p><strong><span style="color: #993300; font-size: small;">To test the installation</span>:</strong></p>
<p>Create a folder c:\temp\ConsoleApp<br /> In this folder, create a file <strong>Program.cs </strong>with these contents:</p>
<p><em>using System;<br /> public class Program<br /> {<br /> &nbsp;&nbsp;&nbsp; public static void Main()<br /> &nbsp;&nbsp;&nbsp; {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine("Hello World");<br /> &nbsp;&nbsp;&nbsp; }<br /> }</em></p>
<p><br /> Also create a file <strong>project.json </strong>with these contents:</p>
<p><em>{<br /> &nbsp;&nbsp;&nbsp; "dependencies": {</em></p>
<p><em>&nbsp;&nbsp;&nbsp; },<br /> &nbsp;&nbsp;&nbsp; "commands": {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "ConsoleApp": "ConsoleApp"<br /> &nbsp;&nbsp;&nbsp; },<br /> &nbsp;&nbsp;&nbsp; "frameworks": {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "dnx451": { },<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "dnxcore50": {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "dependencies": {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "System.Console": "4.0.0-beta-*"<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /> &nbsp;&nbsp;&nbsp; }<br /> }</em></p>
<p><br /> Now using a Command Prompt, go to the folder containing the files and execute the following command:</p>
<p><strong>dnu restore </strong>(this will pull all the required packages into your user folder)<br /> <strong>dnx ConsoleApp</strong></p>
<p>It should print Hello World!</p>
<p>&nbsp;</p>
<p>You can also try the simple CookieSample web app from <a href="https://github.com/aspnet/Security/tree/dev/samples/CookieSample">here</a>.</p>
<p>Note for web apps you have to use the following command to run the development web server (kestrel):</p>
<p><strong>dnx kestrel </strong>(assuming you are currently in the folder containing the project.json file)</p>
<p>&nbsp;</p>
<p><span style="color: #993300; font-size: small;"><strong>Optional Step</strong></span></p>
<p>If you would like to have a convenient way of editing your source files without installing Visual Studio, then check out <a href="https://www.omnisharp.net/">OmniSharp</a>. It is a free plug-in to some popular source editors that supports ASP.NET 5 development. The Atom editor works pretty well on Windows, is lightweight and deploys to the user folder (no admin permissions required). Also install the OmniSharp plugs for Atom.&nbsp;</p>
<p>After you install Atom, close the editor and open a new command prompt and type this command if you use a Proxy Server in your environment:&nbsp;</p>
<p><strong>apm config set https-proxy </strong><strong><a href="https://proxy.server.com:1234">https://proxy.server.com:1234</a></strong></p>
<p>Then issue these commands to install the Atom plug-ins:</p>
<p><strong>apm install autocomplete-plus<br /> apm install linter<br /> apm install omnisharp-atom</strong></p>
<p>Then run Atom and follow the instructions <a href="https://atom.io/packages/omnisharp-atom">here</a> to use the&nbsp;intellisense&nbsp;etc.</p>]]></content:encoded>
    </item>
    <item>
      <title>BHO restrictions in Internet Explorer may cause it to misbehave when accessing Internet websites</title>
      <link>https://docs.microsoft.com/archive/blogs/sujitdmello/bho-restrictions-in-internet-explorer-may-cause-it-to-misbehave-when-accessing-internet-websites</link>
      <pubDate>Tue, 30 Sep 2014 06:32:00 GMT</pubDate>
      <dc:creator><![CDATA[Sujit DMello]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sujitdmello/2014/09/30/bho-restrictions-in-internet-explorer-may-cause-it-to-misbehave-when-accessing-internet-websites/</guid>
      <description><![CDATA[Browser Helper Objects (BHOs) are add-ons in Internet Explorer that extend the functionality of IE....]]></description>
      <content:encoded><![CDATA[<p>Browser Helper Objects (BHOs) are add-ons in Internet Explorer that extend the functionality of IE. Many custom BHOs are written in .NET but what these BHOs are allowed to do is determined by the Zone in which they run.</p>
<p>&nbsp;</p>
<p>If you access an <strong>Intranet</strong> site (Intranet Zone) then your BHO has a medium level trust but if you access an <strong>Internet</strong> site (Internet Zone) then it has a Low level of trust. If your BHO is writing to say some log file, then it is very possible that the File.Open() call will fail due to these restrictions. If you find IE is misbehaving (kept crashing in my case) whenever you access an Internet website, then read on. (Note I discovered this issue on a Windows 8.1 + IE 11 Surface Pro 3, but have not tried it on an older OS).</p>
<p>&nbsp;</p>
<p>As it turns out, besides the usual NTFS permissions, all files and folders also have an 'integrity' level, which is 'Medium' by default. You can use the handy <strong>icacls</strong> command to find information about your integrity level:</p>
<p><em>icacls "c:\\Log"</em></p>
<p>You can look for the presence of this in the displayed output:</p>
<p>&nbsp;<em>Mandatory Label\Low Mandatory Level:(OI)(CI)(NW)</em></p>
<p><em></em>The default is <strong>Medium </strong>if the above is not displayed.</p>
<p>&nbsp;</p>
<p>So what do you do if you need write access in the Internet Zone (low trust)? Issue the <strong>icacls</strong> command as follows:</p>
<p><em>icacls "c:\Log" /T /setintegritylevel (OI)(CI)L​</em></p>
<p>&nbsp;</p>
<p>This will allow BHOs in the Internet Zone to Write to the c:\Log folder. The Zone restrictions are meant to prevent malicious code from unauthorized access to your files and folders so be carefull with this command and only give access to a specific folder.</p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>Global configuration for WebAPI services to add custom extensions</title>
      <link>https://docs.microsoft.com/archive/blogs/sujitdmello/global-configuration-for-webapi-services-to-add-custom-extensions</link>
      <pubDate>Wed, 24 Sep 2014 10:37:00 GMT</pubDate>
      <dc:creator><![CDATA[sujitdmello]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sujitdmello/2014/09/24/global-configuration-for-webapi-services-to-add-custom-extensions/</guid>
      <description><![CDATA[&nbsp;
When you create a WebAPI service, you must configure it in code by adding to the generated...]]></description>
      <content:encoded><![CDATA[<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;">&nbsp;</p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span style="color: #000000; font-family: Calibri;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;">When you create a WebAPI service, you must configure it in code by adding to the generated Register method. There does not seem to be a way to establish a policy-based configuration for ALL WebAPI services on the box. After coming up empty on Bing (and Google!) I decided to read up on <a href="https://www.asp.net/aspnet/overview/owin-and-katana">Katana</a> and found a hook at the OWIN host level which can be used to inject configuration onto these WebAPI apps.</span></span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;">&nbsp;</p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span style="color: #000000; font-family: Consolas;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="font-family: Calibri;">First, write a simple class as follows and make it strongly-typed by signing it and then GAC it (you will need to pull in OWIN and WebAPI libs via NuGet).</span>&nbsp;</span></span><span style="font-family: Calibri;"><span style="color: #000000; font-size: 11pt;">&nbsp;</span></span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><br />&nbsp;</p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;">&nbsp;</p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span style="font-family: Consolas;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #0000ff;"><span style="font-size: 9.5pt;">namespace</span></span></span><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #000000; font-size: 9.5pt;"> WebApi</span></span></span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="font-family: Consolas;"><span style="color: #000000; font-size: 9.5pt;">{</span></span></span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span style="font-family: Consolas;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #000000;"><span style="font-size: 9.5pt;">&nbsp;&nbsp;&nbsp; </span></span></span><span style="font-size: 9.5pt;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #0000ff;">public</span></span><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #0000ff;">class</span></span></span><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #2b91af; font-size: 9.5pt;">WebApiConfiguration</span></span></span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="font-family: Consolas;"><span style="color: #000000; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp; {</span></span></span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span style="font-family: Consolas;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #000000;"><span style="font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span style="font-size: 9.5pt;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #0000ff;">public</span></span><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #0000ff;">void</span></span><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #000000;"> Configuration(</span></span><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #2b91af;">IAppBuilder</span></span></span><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #000000; font-size: 9.5pt;"> app)</span></span></span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="font-family: Consolas;"><span style="color: #000000; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span></span></span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span style="font-family: Consolas;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #000000;"><span style="font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span style="font-size: 9.5pt;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #0000ff;">var</span></span><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #000000;"> config = </span></span><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #2b91af;">GlobalConfiguration</span></span></span><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #000000; font-size: 9.5pt;">.Configuration;</span></span></span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="font-family: Consolas;"><span style="color: #000000; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ConfigureAuth(app);</span></span></span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="font-family: Consolas;"><span style="color: #000000; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ConfigureExtensions(config);</span></span></span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="font-family: Consolas;"><span style="color: #000000; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></span></span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="font-family: Consolas;"><span style="color: #000000; font-size: 9.5pt;">&nbsp;</span></span></span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span style="font-family: Consolas;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #000000;"><span style="font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span style="font-size: 9.5pt;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #0000ff;">public</span></span><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #0000ff;">static</span></span><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #0000ff;">void</span></span><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #000000;"> ConfigureExtensions(</span></span><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #2b91af;">HttpConfiguration</span></span></span><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #000000; font-size: 9.5pt;"> config)</span></span></span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="font-family: Consolas;"><span style="color: #000000; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span></span></span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span style="font-family: Consolas;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #000000;"><span style="font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; config.Filters.Add(</span></span></span><span style="font-size: 9.5pt;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #0000ff;">new</span></span><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #2b91af;">MyAuthFilter</span></span></span><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #000000; font-size: 9.5pt;">());</span></span></span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span style="font-family: Consolas;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #000000;"><span style="font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; config.MessageHandlers.Add(</span></span></span><span style="font-size: 9.5pt;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #0000ff;">new</span></span><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #2b91af;">MyDelegatingHandler</span></span></span><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #000000; font-size: 9.5pt;">());</span></span></span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span style="font-family: Consolas;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #000000;"><span style="font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; config.Filters.Add(</span></span></span><span style="font-size: 9.5pt;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #0000ff;">new</span></span><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #2b91af;">MyExceptionFilterAttribute</span></span></span><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #000000; font-size: 9.5pt;">());</span></span></span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span style="font-family: Consolas;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #000000;"><span style="font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; config.Filters.Add(</span></span></span><span style="font-size: 9.5pt;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #0000ff;">new</span></span><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #2b91af;">MyActionFilterAttribute</span></span></span><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #000000; font-size: 9.5pt;">());</span></span></span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span style="font-family: Consolas;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #000000;"><span style="font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; config.Formatters.Add(</span></span></span><span style="font-size: 9.5pt;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #0000ff;">new</span></span><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #2b91af;">MyMediaTypeFormatter</span></span></span><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #000000; font-size: 9.5pt;">());</span></span></span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="font-family: Consolas;"><span style="color: #000000; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></span></span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="font-family: Consolas;"><span style="color: #000000; font-size: 9.5pt;">&nbsp;</span></span></span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span style="font-family: Consolas;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #000000;"><span style="font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span style="font-size: 9.5pt;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #0000ff;">public</span></span><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #0000ff;">void</span></span><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #000000;"> ConfigureAuth(</span></span><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #2b91af;">IAppBuilder</span></span></span><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #000000; font-size: 9.5pt;"> app)</span></span></span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="font-family: Consolas;"><span style="color: #000000; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span></span></span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span style="font-family: Consolas;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #000000;"><span style="font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; app.UseCookieAuthentication(</span></span></span><span style="font-size: 9.5pt;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #0000ff;">new</span></span><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #2b91af;">CookieAuthenticationOptions</span></span></span><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #000000; font-size: 9.5pt;">());</span></span></span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span style="font-family: Consolas;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #000000;"><span style="font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; app.UseExternalSignInCookie(</span></span></span><span style="font-size: 9.5pt;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #2b91af;">DefaultAuthenticationTypes</span></span></span><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="color: #000000; font-size: 9.5pt;">.ExternalCookie);</span></span></span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="font-family: Consolas;"><span style="color: #000000; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></span></span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="font-family: Consolas;"><span style="color: #000000; font-size: 9.5pt;">&nbsp;</span></span></span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;"><span style="font-family: Consolas;"><span style="color: #000000; font-size: 9.5pt;">&nbsp;&nbsp;&nbsp; }</span></span></span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span><span style="font-family: Consolas;"><span style="color: #000000; font-size: 9.5pt;">&nbsp;</span></span></span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span><span style="font-family: Consolas;"><span style="color: #000000; font-size: 9.5pt;">&hellip; other classes left out for brevity.</span></span></span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;">&nbsp;</p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span style="color: #000000; font-family: Calibri;"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%;">The main method is <em>Configuration </em>which gets called by the OWIN host &ndash; but only if it finds a particular setting in the appSettings configuration. What was surprising (to me) is that you can have a &lsquo;global&rsquo; set of appSettings in the global web.config file. Just add the following to the web.config file located in c:\windows\microsoft.net\framework\v4.0.30319\config:</span></span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;">&nbsp;</p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><em><span style="font-family: Calibri;"><span style="color: #000000; font-size: 11pt;">&nbsp; &lt;appSettings&gt;</span></span></em></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><em><span style="font-family: Calibri;"><span style="color: #000000; font-size: 11pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;add key="owin:appStartup" value="WebApiConfiguration, WebApiExtension, Version=1.0.0.0, Culture=neutral, PublicKeyToken=fc3a6ca1f8e86de8" /&gt;</span></span></em></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><em><span style="font-family: Calibri;"><span style="color: #000000; font-size: 11pt;">&nbsp;&nbsp;&nbsp; &lt;/appSettings&gt;</span></span></em></p>
<p>&nbsp;</p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span style="color: #000000; font-family: Calibri;">Now any WebAPI app on that box will automatically pull in your custom extensions so you can have your own hooks into these apps. From an enterprise perspective, you can plugin your own tracing, exception handling, Action filters, authentication etc. And the app developer needs not do anything special so there is nothing new to learn. It was pointed out to me that this will setting will override the Startup class in the app. In our case this is a good thing as we want to enforce certain behaviors on the app.</span></p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;">&nbsp;</p>
<p class="MsoNormal" style="list-style-type: disc; margin: 0in 0in 0pt;"><span style="color: #000000; font-family: Calibri;">BTW I used Web API 2.2 for this POC.</span></p>]]></content:encoded>
    </item>
    <item>
      <title>Using Angular.JS with ASP.NET AJAX libraries to call WCF REST services</title>
      <link>https://docs.microsoft.com/archive/blogs/sujitdmello/using-angular-js-with-asp-net-ajax-libraries-to-call-wcf-rest-services</link>
      <pubDate>Fri, 10 Jan 2014 11:11:00 GMT</pubDate>
      <dc:creator><![CDATA[sujitdmello]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sujitdmello/2014/01/10/using-angular-js-with-asp-net-ajax-libraries-to-call-wcf-rest-services/</guid>
      <description><![CDATA[WCF has enabled building of REST services via the WebGet and WebInvoke attributes and the...]]></description>
      <content:encoded><![CDATA[<p>WCF has enabled building of REST services via the <em>WebGet </em>and <em>WebInvoke </em>attributes and the <em>WebHttpBinding</em>. This makes it easy to expose a ServiceContract as a REST service. Consuming this service from JavaScript is not too difficult and you can use jQuery, Angular.JS etc. to make it easier. But when you have to access many services in this way you want to be able to use the generated JavaScript proxy (available at the <a href="https://machine/service/service.svc/js">https://machine/service/service.svc/js</a> endpoint of the WCF REST service). The nice part about this proxy is that it preserves the namespace of your service and gives a nice object-oriented way of calling the service like so:</p>
<pre class="csharpcode"><span class="kwrd">var</span> proxy = <span class="kwrd">new</span> tempuri.org.IService();
proxy.GetDataREST(id, successRESTService, errorRESTService, <span class="kwrd">null</span>);             </pre>
<p>The problem with this proxy is that it has a dependency on the ASP.NET <em>ScriptManager</em> server controls so you generally have to include it within an ASPX page. However in the day of HTML+JS apps you can use this with a plain HTML file if you know which JS library to include from the ASP.NET CDN:</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">script</span> <span class="attr">src</span><span class="kwrd">="https://ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js"</span><span class="kwrd">&gt;&lt;/</span><span class="html">script</span><span class="kwrd">&gt;</span></pre>
<p>This will include the compressed and obfuscated ASP.NET JS library that has the helper functions required to use the generated service proxy. Now recently I&rsquo;ve gotten to love Angular.JS and I thought of using that framework to write a tiny HTML app that calls a WCF REST service using the generated proxy. Off course it generally works fine with one big problem. The callbacks used by the ASP.NET AJAX libraries (<em>successRESTService</em> and <em>errorRESTService</em> in the example above) don&rsquo;t seem to work the same way as the <em>Promises </em>used by Angular.JS. As a result, although the callback is invoked correctly, none of the bindings are updated during the callback. So the view elements do not show the data returned form the web service. However, I was able to force the view to update by calling <em>$scope.$digest(); </em>at the end of the callback method. So the completed app looks like so:</p>
<pre class="csharpcode"><span class="kwrd">&lt;!</span><span class="html">doctype</span> <span class="attr">html</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">html</span> <span class="attr">ng-app</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">head</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">title</span><span class="kwrd">&gt;</span>Call REST service via Angular<span class="kwrd">&lt;/</span><span class="html">title</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">script</span> <span class="attr">src</span><span class="kwrd">="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js"</span><span class="kwrd">&gt;&lt;/</span><span class="html">script</span><span class="kwrd">&gt;</span>
    &lt;script src=<span class="str">"https://ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js"</span>&gt;&lt;/script&gt;
    &lt;script src=<span class="str">"https://localhost/RESTJSONCompare/Service.svc/js"</span>&gt;&lt;/script&gt;
    &lt;script type=<span class="str">"text/javascript"</span>&gt;
        <span class="kwrd">var</span> ServiceController = <span class="kwrd">function</span> ($scope, $http) {
            <span class="kwrd">var</span> id = 123;
            $scope.getPerson = <span class="kwrd">function</span> () {
                <span class="kwrd">var</span> proxy = <span class="kwrd">new</span> tempuri.org.IService();
                proxy.GetDataREST(id, successRESTService, errorRESTService, <span class="kwrd">null</span>);               
                $scope.ErrorMessage = <span class="str">""</span>;
            }
            <span class="kwrd">var</span> successRESTService = <span class="kwrd">function</span> (data) {
                $scope.PersonID = data.ID;
                $scope.PersonName = data.Name;
                $scope.PersonAddress = data.Address;
                $scope.$digest();
            }
            <span class="kwrd">var</span> errorRESTService = <span class="kwrd">function</span> (data) {
                $scope.ErrorMessage = <span class="str">"HTTP error code : "</span> + data;
                $scope.$digest();
            }
        };
    <span class="kwrd">&lt;/</span><span class="html">script</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">head</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">body</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">div</span> <span class="attr">ng-controller</span><span class="kwrd">="ServiceController"</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">input</span> <span class="attr">type</span><span class="kwrd">="button"</span> <span class="attr">ng-click</span><span class="kwrd">="getPerson();"</span> <span class="attr">value</span><span class="kwrd">="Call REST Service"</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">hr</span> <span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">ul</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">li</span><span class="kwrd">&gt;</span>
                ID: {{PersonID}}
            <span class="kwrd">&lt;/</span><span class="html">li</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">li</span><span class="kwrd">&gt;</span>
                Name: {{PersonName}}
            <span class="kwrd">&lt;/</span><span class="html">li</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">li</span><span class="kwrd">&gt;</span>
                Address: {{PersonAddress}}
            <span class="kwrd">&lt;/</span><span class="html">li</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">ul</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">label</span><span class="kwrd">&gt;</span>{{ErrorMessage}}<span class="kwrd">&lt;/</span><span class="html">label</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">body</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">html</span><span class="kwrd">&gt;</span>
</pre>
<p>This gives you the best of both worlds, the power of Angular.JS data binding and the simplicity of the ASP.NET AJAX proxies + WCF REST services.</p>
<p><em>By popular demand, I have also uploaded the WCF service to this post.</em></p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/10/48/88/65/RESTJSONCompare.zip" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-10-48-88-65/RESTJSONCompare.zip">RESTJSONCompare.zip</a></p>]]></content:encoded>
    </item>
    <item>
      <title>IPC between Windows Store Apps on the same machine</title>
      <link>https://docs.microsoft.com/archive/blogs/sujitdmello/ipc-between-windows-store-apps-on-the-same-machine</link>
      <pubDate>Sat, 13 Apr 2013 08:48:00 GMT</pubDate>
      <dc:creator><![CDATA[sujitdmello]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sujitdmello/2013/04/13/ipc-between-windows-store-apps-on-the-same-machine/</guid>
      <description><![CDATA[Windows Store Apps are the new modern way to build applications for the Windows 8 platform. For many...]]></description>
      <content:encoded><![CDATA[<p>Windows Store Apps are the new modern way to build applications for the Windows 8 platform. For many of us coming from WinForms on WPF backgrounds, one area of difficulty is with the way Windows Store Apps are sandboxed. This isolation makes it nearly impossible for them to talk to each other. Just to be clear, IPC is not a use-case most consumer-facing applications need. However when you start developing LOB apps, IPC suddenly becomes important, and in some cases a must-have.</p>  <p>One approach to get around the Sandboxing is to use the oldest form of IPC – the file system. However this still needs a common file/folder that all apps can access. By default, apps have their own private isolated storage that is not accessible by other apps. But you can give the apps the capability to access the user’s Documents folder <em>for specific file types</em>. So I went down the road of using a shared folder with a bunch of files as a means of communications and was surprised how well it worked. Off course you can’t expect the file system notification to handle very rapid changes, but for many scenarios, this scale works (think FileSystemWatcher). </p>  <p>I’ve wrapped all the functionality into an easy-to-use WinMD module (that is accessible from both WinJS and C# apps). Here are some of the highlights of the library:</p>  <h3>Overview</h3>  <p>The general idea is fairly simple, implement a Publish/Subscribe mechanism by using shared files. WinRT has a mechanism to detect changes to a folder so we leverage that facility to detect the changes and call a delegate within the registered application. As a convention, I used a folder named <em>Topics</em> and in that folder are various files with the <strong>.topic </strong>extension. This allows various types of publish/subscribe events to be fired and applications need only listen to the one they are interested in.</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/14/56/metablogapi/4532.File-Notification_03C602FD.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-14-56-metablogapi/4532.File_2D00_Notification_5F00_03C602FD.png"><img title="File Notification" style="display: inline; background-image: none;" border="0" alt="File Notification" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/14/56/metablogapi/4135.File-Notification_thumb_4323B68D.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-14-56-metablogapi/4135.File_2D00_Notification_5F00_thumb_5F00_4323B68D.png" width="536" height="454" /></a>&#160; </p>  <p>First here is the snippet to write the application provided payload to the file. The application calls the NotifyApps method to Publish something new:</p>  <pre class="code"><span style="background: white; color: blue;">public async void </span><span style="background: white; color: black;">NotifyApps(</span><span style="background: white; color: blue;">string </span><span style="background: white; color: black;">Payload)
{
     </span><span style="background: white; color: rgb(43, 145, 175);">StorageFolder </span><span style="background: white; color: black;">folder = </span><span style="background: white; color: rgb(43, 145, 175);">KnownFolders</span><span style="background: white; color: black;">.DocumentsLibrary;
     folder = </span><span style="background: white; color: blue;">await </span><span style="background: white; color: black;">folder.CreateFolderAsync(TopicsFolder, </span><span style="background: white; color: rgb(43, 145, 175);">CreationCollisionOption</span><span style="background: white; color: black;">.OpenIfExists);
     </span><span style="background: white; color: rgb(43, 145, 175);">StorageFile </span><span style="background: white; color: black;">f = </span><span style="background: white; color: blue;">await </span><span style="background: white; color: black;">folder.CreateFileAsync(SharedFile, </span></pre>

<pre class="code"><span style="background: white; color: black;">        </span><span style="background: white; color: rgb(43, 145, 175);">CreationCollisionOption</span><span style="background: white; color: black;">.OpenIfExists);
     </span><span style="background: white; color: blue;">await </span><span style="background: white; color: black;">Windows.Storage.</span><span style="background: white; color: rgb(43, 145, 175);">FileIO</span><span style="background: white; color: black;">.WriteTextAsync(f, Payload);
}</span></pre>

<p>&#160;</p>

<p>Now there is no FileSystemWatcher in WinRT but we do have a mechanism to monitor a folder for changes. So we can leverage that to achieve our goal as follows. Note we take a delegate from the application and save it for later. And we set the StorageFileQueryResult to call our delegate when any changes are detected via the ContentsChanged event. Applications using the library call Subscribe if they wish to receive notifications for a particular topic: </p>

<pre class="code"><span style="background: white; color: blue;">public async void </span><span style="background: white; color: black;">Subscribe(</span><span style="background: white; color: rgb(43, 145, 175);">NotificationReceived </span><span style="background: white; color: black;">NotificationCallback)
{
    callback = NotificationCallback;
    folder = </span><span style="background: white; color: rgb(43, 145, 175);">KnownFolders</span><span style="background: white; color: black;">.DocumentsLibrary;
    folder = </span><span style="background: white; color: blue;">await </span><span style="background: white; color: black;">folder.CreateFolderAsync(TopicsFolder, </span></pre>

<pre class="code"><span style="background: white; color: black;">       </span><span style="background: white; color: rgb(43, 145, 175);">CreationCollisionOption</span><span style="background: white; color: black;">.OpenIfExists);
    </span><span style="background: white; color: rgb(43, 145, 175);">QueryOptions </span><span style="background: white; color: black;">qo = </span><span style="background: white; color: blue;">new </span><span style="background: white; color: rgb(43, 145, 175);">QueryOptions</span><span style="background: white; color: black;">();
    qo.FileTypeFilter.Add(SharedFileExtension);
    query = folder.CreateFileQueryWithOptions(qo);
    query.ContentsChanged += query_ContentsChanged;
    </span><span style="background: white; color: blue;">await </span><span style="background: white; color: black;">query.GetFilesAsync();
}
</span></pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>

<p><font color="#000000" face="Courier New"></font></p>

<p><font color="#000000">And in the ContentsChanged event we simply read the file and call the application registered delegate. Note we also check if the Payload has changed since the last event.</font></p>

<pre class="code"><span style="background: white; color: black;">f = </span><span style="background: white; color: blue;">await </span><span style="background: white; color: black;">folder.GetFileAsync(SharedFile);

</span><span style="background: white; color: rgb(43, 145, 175);">IInputStream </span><span style="background: white; color: black;">stream = </span><span style="background: white; color: blue;">await </span><span style="background: white; color: black;">f.OpenReadAsync();
</span><span style="background: white; color: blue;">using </span><span style="background: white; color: black;">(</span><span style="background: white; color: rgb(43, 145, 175);">DataReader </span><span style="background: white; color: black;">reader = </span><span style="background: white; color: blue;">new </span><span style="background: white; color: rgb(43, 145, 175);">DataReader</span><span style="background: white; color: black;">(stream))
{
    </span><span style="background: white; color: blue;">var </span><span style="background: white; color: black;">read = </span><span style="background: white; color: blue;">await </span><span style="background: white; color: black;">reader.LoadAsync(MAX_PAYLOAD_LENGTH);
    </span><span style="background: white; color: blue;">string </span><span style="background: white; color: black;">CurrentPayload = reader.ReadString(read);
    </span><span style="background: white; color: blue;">if </span><span style="background: white; color: black;">(CurrentPayload != LastPayload)
    {
        callback(CurrentPayload);
        LastPayload = CurrentPayload;
    }
}
</span></pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>

<pre class="code"><span style="background: white; color: black;"><font face="Segoe UI"></font></span></pre>

<pre class="code"><span style="background: white; color: black;"><font face="Segoe UI"></font></span></pre>

<pre class="code"><span style="background: white; color: black;"><font face="Segoe UI"></font></span></pre>

<pre class="code"><span style="background: white; color: black;"><font face="Segoe UI"></font></span></pre>

<pre class="code"><span style="background: white; color: black;"><font face="Segoe UI"></font></span></pre>

<pre class="code"><span style="background: white; color: black;"><font face="Segoe UI"></font></span></pre>

<h5>Sample App code to publish information:</h5>

<h4><span style="background: white; color: black;"><font face="Segoe UI"></font></span></h4>

<pre class="code"><span style="background: white; color: black;">StartupTech.WindowsStore.Library.</span><span style="background: white; color: rgb(43, 145, 175);">ApplicationNotification </span><span style="background: white; color: black;">notify = </span></pre>

<pre class="code"><span style="background: white; color: black;"></span><span style="background: white; color: blue;">new </span><span style="background: white; color: black;">StartupTech.WindowsStore.Library.</span><span style="background: white; color: rgb(43, 145, 175);">ApplicationNotification</span><span style="background: white; color: black;">(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;AccountNumber&quot;</span><span style="background: white; color: black;">);
notify.NotifyApps(StatusTextBox.Text);</span></pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>

<h5>Sample App code to consume notifications</h5>

<pre class="code"><span style="background: white; color: black;">StartupTech.WindowsStore.Library.</span><span style="background: white; color: rgb(43, 145, 175);">ApplicationNotification </span><span style="background: white; color: black;">notify = </span><span style="background: white; color: blue;">new </span></pre>

<pre class="code"><span style="background: white; color: blue;"></span><span style="background: white; color: black;">StartupTech.WindowsStore.Library.</span><span style="background: white; color: rgb(43, 145, 175);">ApplicationNotification</span><span style="background: white; color: black;">(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;AccountNumber&quot;</span><span style="background: white; color: black;">);
notify.Subscribe(ReceivedNotification);</span></pre>

<pre class="code"><span style="background: white; color: black;"><font face="Segoe UI"><pre class="code"><span style="background: white; color: blue;">void </span><span style="background: white; color: black;">ReceivedNotification(</span><span style="background: white; color: blue;">string </span><span style="background: white; color: black;">Payload)
{
     SetStatus(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;Payload received : &quot; </span><span style="background: white; color: black;">+ Payload);
}</span></pre>The complete project for the <em>AppNotification </em>library can be found <a href="https://skydrive.live.com/redir?resid=DB1D513C602887B4!84720&amp;authkey=!AP19RdOGIAE8hsk">here</a>.</font></span></pre>

<pre class="code"><span style="background: white; color: black;"><font face="Segoe UI"></font></span></pre>

<pre class="code"><span style="background: white; color: black;"><font face="Segoe UI"></font></span></pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>

<pre class="code"><span style="background: white; color: black;"></span></pre>

<p><em>Just a reminder to <a href="https://msdn.microsoft.com/en-us/library/windows/apps/hh464936.aspx">add the Documents folder capability</a> to your Windows Store application and configure it for the <strong>.topic</strong> file extension. That is the only file extension you can access from your app.</em></p>

<p>If you need Windows Apps to communicate across machines you can look at SignalR instead. See my <a href="https://blogs.msdn.com/b/sujitdmello/archive/2013/03/31/using-signalr-for-net-gt-net-scenarios.aspx">post</a> on this scenario.</p>]]></content:encoded>
    </item>
    <item>
      <title>Using SignalR for .NET–&gt; .NET scenarios</title>
      <link>https://docs.microsoft.com/archive/blogs/sujitdmello/using-signalr-for-net-net-scenarios</link>
      <pubDate>Sun, 31 Mar 2013 05:15:00 GMT</pubDate>
      <dc:creator><![CDATA[sujitdmello]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sujitdmello/2013/03/31/using-signalr-for-net-net-scenarios/</guid>
      <description><![CDATA[SignalR is an amazing library for creating real-time applications that are constantly being updated...]]></description>
      <content:encoded><![CDATA[<p><a href="https://signalr.net/">SignalR</a> is an amazing library for creating real-time applications that are constantly being updated with new information. The focus has been on web applications but it turns out that the libraries do support .NET servers and clients. I found very few actual samples of such scenarios so I put one together. What will strike you first is how little code is required to get a real-time client-server notification system up and running. SignalR libraries do all the heavy lifting for you. </p>  <p>Note that these samples were tested with Visual Studio 2012 + Update 1.</p>  <p>From the <a href="https://github.com/SignalR/SignalR/wiki/Self-host">SignalR</a> site, here are the NuGet packages you need to pull into your self-hosted server app:</p>  <p><font size="1" face="Courier New">Install-Package Microsoft.Owin.Hosting –pre</font></p> <font size="1" face="Courier New"></font>  <p><font size="1" face="Courier New">Install-Package Microsoft.Owin.Host.HttpListener –pre </font></p> <font size="1" face="Courier New"></font>  <p><font size="1" face="Courier New">Install-Package Microsoft.AspNet.SignalR.Owin</font></p>  <p><font size="1">And the server code is here:</font></p>  <pre class="code"><span style="background: white; color: blue;">using </span><span style="background: white; color: black;">System;
</span><span style="background: white; color: blue;">using </span><span style="background: white; color: black;">Microsoft.AspNet.SignalR;
</span><span style="background: white; color: blue;">using </span><span style="background: white; color: black;">Microsoft.Owin.Hosting;
</span><span style="background: white; color: blue;">using </span><span style="background: white; color: black;">Owin;
</span><span style="background: white; color: blue;">using </span><span style="background: white; color: black;">Microsoft.AspNet.SignalR.Hubs;

</span><span style="background: white; color: blue;">namespace </span><span style="background: white; color: black;">SignalRNotifier
{
    </span><span style="background: white; color: blue;">class </span><span style="background: white; color: rgb(43, 145, 175);">Program
    </span><span style="background: white; color: black;">{
        </span><span style="background: white; color: blue;">static void </span><span style="background: white; color: black;">Main(</span><span style="background: white; color: blue;">string</span><span style="background: white; color: black;">[] args)
        {
            </span><span style="background: white; color: blue;">string </span><span style="background: white; color: black;">url = </span><span style="background: white; color: rgb(163, 21, 21);">&quot;https://localhost:8080&quot;</span><span style="background: white; color: black;">;

            </span><span style="background: white; color: blue;">using </span><span style="background: white; color: black;">(</span><span style="background: white; color: rgb(43, 145, 175);">WebApplication</span><span style="background: white; color: black;">.Start&lt;</span><span style="background: white; color: rgb(43, 145, 175);">Startup</span><span style="background: white; color: black;">&gt;(url))
            {
                </span><span style="background: white; color: rgb(43, 145, 175);">Console</span><span style="background: white; color: black;">.WriteLine(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;Server running on {0}&quot;</span><span style="background: white; color: black;">, url);

                </span><span style="background: white; color: blue;">string </span><span style="background: white; color: black;">c = </span><span style="background: white; color: rgb(43, 145, 175);">Console</span><span style="background: white; color: black;">.ReadLine();
                </span><span style="background: white; color: blue;">while </span><span style="background: white; color: black;">(!</span><span style="background: white; color: blue;">string</span><span style="background: white; color: black;">.IsNullOrEmpty(c))
                {
                    </span><span style="background: white; color: blue;">if </span><span style="background: white; color: black;">(c == </span><span style="background: white; color: rgb(163, 21, 21);">&quot;S&quot;</span><span style="background: white; color: black;">) </span><span style="background: white; color: green;">// Send a message to all clients.
                    </span><span style="background: white; color: black;">{
                        </span><span style="background: white; color: rgb(43, 145, 175);">GlobalHost</span><span style="background: white; color: black;">.ConnectionManager.GetHubContext&lt;</span><span style="background: white; color: rgb(43, 145, 175);">MyHub</span><span style="background: white; color: black;">&gt;().Clients.All.addMessage(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;Hello World&quot;</span><span style="background: white; color: black;">);
                    }
                    c = </span><span style="background: white; color: rgb(43, 145, 175);">Console</span><span style="background: white; color: black;">.ReadLine();
                }
            }
        }
    }

    </span><span style="background: white; color: blue;">class </span><span style="background: white; color: rgb(43, 145, 175);">Startup
    </span><span style="background: white; color: black;">{
        </span><span style="background: white; color: blue;">public void </span><span style="background: white; color: black;">Configuration(</span><span style="background: white; color: rgb(43, 145, 175);">IAppBuilder </span><span style="background: white; color: black;">app)
        {
</span><span style="background: white; color: green;">            </span><span style="background: white; color: blue;">var </span><span style="background: white; color: black;">config = </span><span style="background: white; color: blue;">new </span><span style="background: white; color: rgb(43, 145, 175);">HubConfiguration </span><span style="background: white; color: black;">{ EnableCrossDomain = </span><span style="background: white; color: blue;">true </span><span style="background: white; color: black;">};
</span><span style="background: white; color: green;">            </span><span style="background: white; color: black;">app.MapHubs(config);
        }
    }

    [</span><span style="background: white; color: rgb(43, 145, 175);">HubName</span><span style="background: white; color: black;">(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;TestHub&quot;</span><span style="background: white; color: black;">)]
    </span><span style="background: white; color: blue;">public class </span><span style="background: white; color: rgb(43, 145, 175);">MyHub </span><span style="background: white; color: black;">: </span><span style="background: white; color: rgb(43, 145, 175);">Hub
    </span><span style="background: white; color: black;">{
    }
}
</span></pre>

<pre><font face="Segoe UI">For the client app, simply get the client package as follows:</font></pre>

<pre><font size="1">Install-Package Microsoft.AspNet.SignalR.Client</font> </pre>

<pre><font face="Segoe UI">and the client code is extremely simply too:</font></pre>

<pre class="code"><span style="background: white; color: blue;">using </span><span style="background: white; color: black;">Microsoft.AspNet.SignalR.Client.Hubs;
</span><span style="background: white; color: blue;">using </span><span style="background: white; color: black;">System;

</span><span style="background: white; color: blue;">namespace </span><span style="background: white; color: black;">SRClient
{
    </span><span style="background: white; color: blue;">class </span><span style="background: white; color: rgb(43, 145, 175);">Program
    </span><span style="background: white; color: black;">{
        </span><span style="background: white; color: blue;">static void </span><span style="background: white; color: black;">Main(</span><span style="background: white; color: blue;">string</span><span style="background: white; color: black;">[] args)
        {
            </span><span style="background: white; color: blue;">var </span><span style="background: white; color: black;">hub = </span><span style="background: white; color: blue;">new </span><span style="background: white; color: rgb(43, 145, 175);">HubConnection</span><span style="background: white; color: black;">(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;https://localhost:8080&quot;</span><span style="background: white; color: black;">);
            </span><span style="background: white; color: rgb(43, 145, 175);">IHubProxy </span><span style="background: white; color: black;">h = hub.CreateHubProxy(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;TestHub&quot;</span><span style="background: white; color: black;">);
            
            hub.Start().ContinueWith(task =&gt; 
            {
                </span><span style="background: white; color: blue;">if </span><span style="background: white; color: black;">(task.IsFaulted)
                    </span><span style="background: white; color: rgb(43, 145, 175);">Console</span><span style="background: white; color: black;">.WriteLine(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;Failed: {0}&quot;</span><span style="background: white; color: black;">, task.Exception.GetBaseException());
                </span><span style="background: white; color: blue;">else
                </span><span style="background: white; color: black;">{
                    </span><span style="background: white; color: rgb(43, 145, 175);">Console</span><span style="background: white; color: black;">.WriteLine(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;Connected with id {0}&quot;</span><span style="background: white; color: black;">, hub.ConnectionId);
                    h.On(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;addMessage&quot;</span><span style="background: white; color: black;">,  data =&gt; </span><span style="background: white; color: rgb(43, 145, 175);">Console</span><span style="background: white; color: black;">.WriteLine(</span><span style="background: white; color: rgb(163, 21, 21);">&quot;Got the event from the server! [&quot; </span><span style="background: white; color: black;">+ data + </span><span style="background: white; color: rgb(163, 21, 21);">&quot;]&quot;</span><span style="background: white; color: black;">));   
                }
            });
            </span><span style="background: white; color: rgb(43, 145, 175);">Console</span><span style="background: white; color: black;">.ReadLine();
        }
    }
}
</span></pre>

<pre><font face="Segoe UI">You can start multiple clients in different command windows and see all of them get updated near instantaneously.</font></pre>

<pre><font face="Segoe UI">SignalR is great library for many purposes. Get to know it!</font></pre>]]></content:encoded>
    </item>
    <item>
      <title>.NET on a Mac</title>
      <link>https://docs.microsoft.com/archive/blogs/sujitdmello/net-on-a-mac</link>
      <pubDate>Fri, 05 Jun 2009 23:12:00 GMT</pubDate>
      <dc:creator><![CDATA[sujitdmello]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sujitdmello/2009/06/05/net-on-a-mac/</guid>
      <description><![CDATA[I had the need to write some code on my Mac (actually I was too lazy to open up the Win7 laptop) and...]]></description>
      <content:encoded><![CDATA[<P>I had the need to write some code on my Mac (actually I was too lazy to open up the Win7 laptop) and being that I did not want to torture myself by writing it in Xcode, I decided to try the <A href="https://mono-project.com/Start" mce_href="https://mono-project.com/Start">Mono</A> project and write the code in C# instead. I haven't looked at Mono in a while now so I was pleasantly surprised with the ease at which the packages (Mono framework and MonoDevelop IDE) installed on the Mac and then the equal ease with which I quickly copied some code from the web and wrote my little program. It literally took 30 minutes to do the whole thing. Here is a snapshot of the MonoDevelop IDE which has full support for intellisense, compiling etc. The only thing I did not see was a debugger, but I'm sure it's in there somewhere.&nbsp;</P>
<P>The support for .NET seems pretty deep, my code referenced some pretty advanced assemblies and it all worked perfectly. I've only tried console apps and they pretty much cover all aspects of the framework from Xml, Networking, web services etc. WinForms and WebForms support is supposed to be very good too although I haven't tried them yet. If you have a Mac or Linux box, then please check out Mono.&nbsp;</P>
<P mce_keep="true">&nbsp;</P>
<P><IMG src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/09/65/15/35/Mono%20on%20Mac.jpg" original-url="https://blogs.msdn.com/photos/sujitdmello/images/9651535/original.aspx" width=1024 height=640 mce_src="https://blogs.msdn.com/photos/sujitdmello/images/9651535/original.aspx"><BR></P>]]></content:encoded>
    </item>
    <item>
      <title>Setting client behaviors on a MEX connection</title>
      <link>https://docs.microsoft.com/archive/blogs/sujitdmello/setting-client-behaviors-on-a-mex-connection</link>
      <pubDate>Wed, 13 May 2009 12:10:00 GMT</pubDate>
      <dc:creator><![CDATA[sujitdmello]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sujitdmello/2009/05/13/setting-client-behaviors-on-a-mex-connection/</guid>
      <description><![CDATA[Most WCF developers will use MEX at some point in their projects. It is a convenient way to expose...]]></description>
      <content:encoded><![CDATA[<DIV class=ExternalClass9B897774D3694B089D992AEB5E3EAB33>
<P><FONT size=2>Most WCF developers will use MEX at some point in their projects. It is a convenient way to expose and consume metadata about your WCF service. Normally you can use the built-in <EM>MetadataExchangeClient </EM>class which was made specifically for consuming a MEX endpoint. </FONT></P>
<P><FONT size=2>WCF provides you standard bindings for using MEX across the usual set of protocols, HTTP, HTTPS, TCP and named pipes. Here is an example of using the WSHttpBinding:</FONT></P><FONT color=#2b91af size=3><FONT color=#2b91af size=3>
<P><FONT size=2>WSHttpBinding</FONT></FONT></FONT><FONT size=2><FONT color=#000000> mex = (</FONT><FONT color=#2b91af><FONT color=#2b91af>WSHttpBinding</FONT></FONT><FONT color=#000000>)</FONT><FONT color=#2b91af><FONT color=#2b91af>MetadataExchangeBindings</FONT></FONT><FONT color=#000000>.CreateMexHttpBinding(); </FONT><FONT color=#2b91af><FONT color=#2b91af>MetadataExchangeClient</FONT></FONT><FONT color=#000000> mec = </FONT><FONT color=#0000ff><FONT color=#0000ff>new</FONT></FONT><FONT color=#000000> </FONT><FONT color=#2b91af><FONT color=#2b91af>MetadataExchangeClient</FONT></FONT><FONT color=#000000>(mex);</FONT></FONT></P>
<P><FONT color=#000000 size=1></FONT><FONT color=#000000><FONT size=2>In most enterprises you often use custom bindings, so you can replace the binding above with your custom binding – as long as you are using the same custom binding with the service. However, where I hit a road block was in using <EM>custom client behaviors </EM>with <FONT color=#2b91af><FONT color=#2b91af>MetadataExchangeClient. </FONT></FONT><FONT color=#000000>There does not seem to be any obvious way to attach behaviors to the outgoing MEX requests. After doing some experimentation, I realized that the <FONT color=#2b91af><FONT color=#2b91af>MetadataExchangeClient</FONT></FONT> class is extensible and the way to do this is to write a simple class that inherits from it and then override a couple of methods as follows:</FONT></FONT></FONT></P>
<P><FONT size=2><SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue">public</SPAN><SPAN style="FONT-FAMILY: 'Courier New'"><FONT color=#000000> </FONT><SPAN style="COLOR: blue">class</SPAN><FONT color=#000000> </FONT><SPAN style="COLOR: #2b91af">MyMexClient</SPAN><FONT color=#000000> : </FONT><SPAN style="COLOR: #2b91af">MetadataExchangeClient</SPAN></SPAN></FONT> 
<P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'"><FONT color=#000000><FONT size=2>{</FONT></FONT></SPAN></P>
<P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN><FONT color=#000000>&nbsp;&nbsp; </FONT></SPAN><SPAN style="COLOR: #2b91af">Binding</SPAN><FONT color=#000000> MexBinding = </FONT><SPAN style="COLOR: blue">null</SPAN><FONT color=#000000>;</FONT></FONT></SPAN></P>
<P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN><FONT color=#000000>&nbsp;&nbsp; </FONT></SPAN><SPAN style="COLOR: blue">bool</SPAN><FONT color=#000000> RequiresClientCertificate = </FONT><SPAN style="COLOR: blue">false</SPAN><FONT color=#000000>;</FONT></FONT></SPAN></P>
<P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'"><FONT color=#000000 size=2></FONT></SPAN>&nbsp;</P>
<P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN><FONT color=#000000>&nbsp;&nbsp; </FONT></SPAN><SPAN style="COLOR: blue">public</SPAN><FONT color=#000000> MyMexClient(</FONT><SPAN style="COLOR: #2b91af">Binding</SPAN><FONT color=#000000> b): </FONT><SPAN style="COLOR: blue">base</SPAN><FONT color=#000000>(b)</FONT></FONT></SPAN></P>
<P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'"><FONT color=#000000><FONT size=2><SPAN>&nbsp;&nbsp; </SPAN>{</FONT></FONT></SPAN></P>
<P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'"><FONT color=#000000><FONT size=2><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>MexBinding = b;</FONT></FONT></SPAN></P>
<P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'"><FONT color=#000000><FONT size=2><SPAN>&nbsp;&nbsp; </SPAN>}</FONT></FONT></SPAN></P>
<P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'"><FONT color=#000000 size=2></FONT></SPAN>&nbsp;</P>
<P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN><FONT color=#000000>&nbsp;&nbsp; </FONT></SPAN><SPAN style="COLOR: blue">public</SPAN><FONT color=#000000> MyMexClient(</FONT><SPAN style="COLOR: #2b91af">Binding</SPAN><FONT color=#000000> b)</FONT></FONT></SPAN></P>
<P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'"><FONT size=2><FONT color=#000000><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>: </FONT><SPAN style="COLOR: blue">base</SPAN><FONT color=#000000>(b)</FONT></FONT></SPAN></P>
<P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'"><FONT color=#000000><FONT size=2><SPAN>&nbsp;&nbsp; </SPAN>{</FONT></FONT></SPAN></P>
<P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'"><FONT color=#000000><FONT size=2><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>MexBinding = b;</FONT></FONT></SPAN></P>
<P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'"><FONT color=#000000><FONT size=2><SPAN>&nbsp;&nbsp; </SPAN>}</FONT></FONT></SPAN></P>
<P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'"><FONT color=#000000 size=2></FONT></SPAN>&nbsp;</P>
<P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN><FONT color=#000000>&nbsp;&nbsp; </FONT></SPAN><SPAN style="COLOR: blue">protected</SPAN><FONT color=#000000> </FONT><SPAN style="COLOR: blue">override</SPAN><FONT color=#000000> </FONT><SPAN style="COLOR: #2b91af">ChannelFactory</SPAN><FONT color=#000000>&lt;</FONT><SPAN style="COLOR: #2b91af">IMetadataExchange</SPAN><FONT color=#000000>&gt; GetChannelFactory(</FONT><SPAN style="COLOR: #2b91af">EndpointAddress</SPAN><FONT color=#000000> metadataAddress, </FONT><SPAN style="COLOR: blue">string</SPAN><FONT color=#000000> dialect, </FONT><SPAN style="COLOR: blue">string</SPAN><FONT color=#000000> identifier)</FONT></FONT></SPAN></P>
<P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'"><FONT color=#000000><FONT size=2><SPAN>&nbsp;&nbsp; </SPAN>{</FONT></FONT></SPAN></P>
<P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN><FONT color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT></SPAN><SPAN style="COLOR: #2b91af">ChannelFactory</SPAN><FONT color=#000000>&lt;</FONT><SPAN style="COLOR: #2b91af">IMetadataExchange</SPAN><FONT color=#000000>&gt; MexFactory = </FONT><SPAN style="COLOR: blue">new</SPAN><FONT color=#000000> </FONT><SPAN style="COLOR: #2b91af">ChannelFactory</SPAN><FONT color=#000000>&lt;</FONT><SPAN style="COLOR: #2b91af">IMetadataExchange</SPAN><FONT color=#000000>&gt;();</FONT></FONT></SPAN></P>
<P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'"><FONT color=#000000><FONT size=2><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>MexFactory.Endpoint.Binding = MexBinding;</FONT></FONT></SPAN></P>
<P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'"><FONT color=#000000><FONT size=2><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>MexFactory.Endpoint.Address = metadataAddress;</FONT></FONT></SPAN></P>
<P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN><FONT color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT></SPAN><SPAN style="COLOR: green">// Add your client behavior here ...</SPAN></FONT></SPAN></P>
<P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'"><FONT color=#000000><FONT size=2><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>MexFactory.Endpoint.Behaviors.Add(SomeBehavior);</FONT></FONT></SPAN></P>
<P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN><FONT color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT></SPAN><SPAN style="COLOR: blue">return</SPAN><FONT color=#000000> MexFactory;</FONT></FONT></SPAN></P>
<P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'"><FONT color=#000000><FONT size=2><SPAN>&nbsp;&nbsp; </SPAN>}</FONT></FONT></SPAN></P>
<P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'"><FONT color=#000000><FONT size=2>}</FONT></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><FONT color=#000000 size=2 face=Calibri></FONT>&nbsp;</P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><FONT color=#000000 size=2>Now you simply use MyMexClient wherever you would normally use MetadataExchangeClient.</FONT></P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal mce_keep="true">&nbsp;</P></DIV>]]></content:encoded>
    </item>
  </channel>
</rss>