Hi Guys, this week I will show you how I migrated my previous WCF service to be hosted on the Azure cloud instead of Amazon. I decided to follow a two step process: first I will migrate the service as it was previously, that is it will still rely on the AWS API to store and retrieve the data but it will be deployed on Azure, then in the next post I will migrate the code in order to replace Amazon SimpleDb and S3 by Azure Tables and Blob services.
I – Creating a new Azure project
If you haven’t done it yet, you will first need to install the Azure SDK, which is rather straightforward, so I can just skip that step. We then need to create a new “Windows Azure Cloud Service” project:
We then add a “WCF Service Web Role” to our project. That’s the instance that will host our service:
At that point my default project looks as follow:
I am going to remove that default “Service1” and replace it with the existing code I had from my previous project. After including those files in the new project and my two client app, my solution looks like below. At that point I did nothing more than suppressing and including files:
I also cut and paste the content of my old web.config file to the new one. The Azure web.config contains more sections than the one I had before, so I take care about placing the old content at the right place. Also because Azure do not support directly using Net.Tcp from a web role, we will disable the callback functionality and keep only the http and json endpoints.
The Azure config file looks as follow and I am highlighting the portion I was adding myself:
<?xml version="1.0"?>
<configuration>
<configSections>
</configSections>
<!-- To collect diagnostic traces, uncomment the section below or merge with existing system.diagnostics section.
To persist the traces to storage, update the DiagnosticsConnectionString setting with your storage credentials.
To avoid performance degradation, remember to disable tracing on production deployments.
<system.diagnostics>
<sharedListeners>
<add name="AzureLocalStorage" type="WCFServiceWebRole1.AzureLocalStorageTraceListener, WCFServiceWebRole1"/>
</sharedListeners>
<sources>
<source name="System.ServiceModel" switchValue="Verbose, ActivityTracing">
<listeners>
<add name="AzureLocalStorage"/>
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging" switchValue="Verbose">
<listeners>
<add name="AzureLocalStorage"/>
</listeners>
</source>
</sources>
</system.diagnostics> -->
<system.diagnostics>
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener,
Microsoft.WindowsAzure.Diagnostics, Version=1.7.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"
name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
</system.diagnostics>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding
name="AdnCloudServicesBinding"
transferMode="Streamed"
messageEncoding="Mtom"
maxBufferSize="2147483647"
maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647">
<readerQuotas
maxDepth="200"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
</binding>
</basicHttpBinding>
<netTcpBinding>
<binding name="TcpBinding"
hostNameComparisonMode="StrongWildcard"
sendTimeout="00:10:00"
maxReceivedMessageSize="65536"
transferMode="Buffered"
portSharingEnabled="false">
<readerQuotas
maxDepth="200"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
<security mode="None">
<transport clientCredentialType="None"/>
<message clientCredentialType="None"/>
</security>
</binding>
</netTcpBinding>
<webHttpBinding>
<binding
name="webHttpBindingWithJson"/>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="AdnCloudServicesBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="JsonBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service
behaviorConfiguration="AdnCloudServicesBehavior"
name="AdnCloudViewerService.AdnCloudViewerSrv">
<!--endpoint
address="mex"
binding="mexTcpBinding"
contract="IMetadataExchange"/-->
<endpoint
name="WCFCHttpEndpoint"
address=""
binding="basicHttpBinding"
bindingConfiguration="AdnCloudServicesBinding"
contract="AdnCloudViewerService.IAdnCloudViewerSrv"/>
<!--endpoint
name="WCFNetTcpEndpoint"
bindingConfiguration="TcpBinding"
binding="netTcpBinding"
contract="AdnCloudViewerService.IAdnCloudViewerSrv"
address="Viewer"/>
<endpoint
name="WCFCallbackEndpoint"
bindingConfiguration="TcpBinding"
binding="netTcpBinding"
contract="AdnCloudViewerService.IAdnCloudViewerNotification"
address="Callback"/-->
<endpoint
name="WCFRestClientEndpoint"
address="rest"
binding="webHttpBinding"
behaviorConfiguration="JsonBehavior"
bindingConfiguration="webHttpBindingWithJson"
contract="AdnCloudViewerService.IAdnCloudViewerSrvRest"/>
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true "/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
The service is now ready to be built. if the build is successful, you should be able to debug it as you would do for a classic .Net application and it is pretty cool because Visual Studio will launch the compute and storage Azure emulators on your machine and you can test your service locally, including using breakpoints. No manual action is required for this local deployment.
-
II – Deploying the service on Azure
-
Once you are done with testing locally, it’s time to place the service on the cloud. First step is to generate the deployment package. Right click your service project
and select “Package…”. This should generate two files:
- ServiceConfiguration.Cloud.cscfg
- ServiceName.cspkg
The first one is the Azure configuration file, the second contains the whole Azure package (binaries and so on…)
-
You then need to log on into the Azure management console (of course after having sign up for the services or take advantage of the free trial offer):
https://manage.windowsazure.com
Go to the “CLOUD SERVICES”, then +NEW. You can see in my case a colleague already deployed a service on our common account:
You’ve then got to upload your package files and set a couple of options, especially the name of your service and your public base address in “ServiceName”.cloudapp.net:
If you’ve done everything ok, your service should be up and running after a few minutes… easy! You can check the attachment for a complete reference. Next week I will show you how to migrate the code to rely on Azure APIs, cheers!
Comments
You can follow this conversation by subscribing to the comment feed for this post.