Thursday, February 09, 2012

Deploy Silverlight UI with all supporting files into Window Azure


Deploy Silverlight UI with all supporting files into Window Azure

Normally when you deploy your Silverlight 5.0 project you might have couple of supporting files like DLL’s, Images, .zip etc.

And when you deploy your project into on Premises (Normal Servers) then you normally deploy all your supporting files into deployment servers and your Silverlight application read that files from there with Relative path option.

But the case will be little different when you deploy same Silverlight 5.0 application into Window Azure (Howto create and deploy Silverlight application into Window Azure), all the supporting files/folders you cannot deploy into the Window Azure as same you normally do it in on premises.
There are two options to do the things
  1. You can utilized Window Azure blob storage to store all your supporting files/folders, Upload all your files into Window Azure Blob and change in your Silverlight code to read that files/folders from blob. You can see couple of links to understand Howto upload/download files into Window Azure Blob’ 
  2. Second option if you don’t want to use Blob storage, you can combine into same package (Window Azure Package) and you are good to go, but for doing this you need to do following changes into your Silverlight1.Web Project  

    • Move all your supporting files/folders from SilverlightUX.proj to Silverlight.Web.proj
    • Change your Silverlight code to read files/folders from new path you changed
    • Go to the file, right click and open the properties window and set properties as below
                      (For XML, .zip, .txt etc. files)

      • Build Action  à Content
      • Copy to Output Directory à Do Not copy
                       (For Ref DLL's)
      • Copy Local à True

Now all Silverlight supporting files will be bind with Window Azure package and no need to do any configuration changes require.

Useful links

Wednesday, February 08, 2012

How to read Config file value deployed into Window Azure from Silverlight 5.0 code.


How to read Config file value deployed into Window Azure from Silverlight 5.0 code.

If you are planning to move your Silverlight application into Window Azure and you have some configuration value which will be used on your application at runtime then you have to read config file value in different way.

If you have normal Silverlight application then it is simple to read value from Web.config file but if you moved your Silverlight application into window Azure then Web.config file cannot be used on Cloud. 
In that case you have to call window Azure config file (‘.cscfg’) file from SilverlightTest.aspx file and pass into App.xmal so that it can be used in application. see below picture


Solution Structure


Please follow the steps to create demo for this

Steps-1
Create the Project Solution and add Silverlight project and Window Azure Project on it.

Steps-2
Go to Project: SilverlightApplication1.Web.proj and Add reference from
$\Program Files\Windows Azure SDK\v1.6\ref\Microsoft.WindowsAzure.ServiceRuntime.dll 

Steps-3
Go to Project: SilverlightApplication1.Web.proj and Open Web.Config file and add following lines into it
<appSettings>
    <add key="GetFilePath" value="Get value from On Premises Config file"/>
appSettings>

Steps-4
Go to Project: WindowsAzureProject.ccproj and Open ServiceDefinition.csdef file and add following lines into it.
<ConfigurationSettings> 
  <Setting name="GetFilePath"/>
ConfigurationSettings> 

Steps-5
Go to Project: WindowsAzureProject.ccproj and open ServiceConfiguration.Cloud.cscfg and ServiceConfiguration.Local.cscfg and add following lines into it
 <ConfigurationSettings>
   <Setting name="GetFilePath" value="Get value from Window Azure Config file"/>
ConfigurationSettings>

Steps-6
Go to Project: SilverlightApplication1.Web.proj and SilverlightApplication1TestPage.aspx files and add following lines into it

<%@ Import Namespace="Microsoft.WindowsAzure.ServiceRuntime" %>

<param name="Initparams" value="ConfigKey1=<%=RoleEnvironment.IsAvailable ?RoleEnvironment.GetConfigurationSettingValue("GetFilePath") :ConfigurationManager.AppSettings["GetFilePath"]%>, ConfigKey2="Text to test"" />

Note: IF Project has been deployed into On Premises then read value from Web.Config file, IF Project has been deployed into Window Azure then read value from ServiceConfiguration.Cloud.cscfg and ServiceConfiguration.Local.cscfg files.

Steps-7
Go to Project: SilverlightApplication1.proj and Open App.xaml.cs file and on the Application_Startup() event write following code into it
private void Application_Startup(object sender, StartupEventArgs e)
{
   //initialize InitParam value
   IDictionary<string, string> initParams = e.InitParams;
   //Read value from config
   string valueFromConfigKey1 = initParams["ConfigKey1"].ToString();
   string valueFromConfigKey2 = initParams["ConfigKey2"].ToString();
}

Steps-8
Set the Startup project as “WindowsAzureProject.ccproj” and put the break point into Application_Startup() event You will get the value into “valueFromConfigKey1” and 2 variable are

valueFromConfigKey1  = Get value from Window Azure Config file”
valueFromConfigKey2  =  Text to test 

Steps-9
Set the Startup project as “SilverlightApplication1.Web.proj” and put the break point into Application_Startup() event You will get the value into “ valueFromConfigKey1” and 2 variable are

valueFromConfigKey1  = Get value from On Premises Config file
valueFromConfigKey2  =  Text to test 

Note: you can add multiple value into "Initparams" in same way as above.

Friday, February 03, 2012

Cannot find 'ServiceReferences.ClientConfig' in the .xap application package. This file is used to configure client proxies for web services,......


Error: Cannot find 'ServiceReferences.ClientConfig' in the .xap application package. This file is used to configure client proxies for web services, and allows the application to locate the services it needs. Either include this file in the application package, or modify your code to use a client proxy constructor that specifies the service address and binding explicitly.

I received above error when I tried to write some code in App.XML file, I found link below exactly same I was doing, I solved this error from below link


Thursday, February 02, 2012

Window Azure Error: One of the request inputs is out of range

Window Azure Error: One of the request inputs is out of range


I got his error when I was working with window azure blob Storage code

It's simple code but I got this error and not able to figure why, then I compare the code from MSDN only different I found the input parameter going with one upper case letter. Don't know what is the logic not accepting upper case character but when I change all as lower case then this error resolved.


C# Code

 // create blob container for images

blobStorage = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobStorage.GetContainerReference("Mypics");
container.CreateIfNotExist(); 


Error in above code
  • 'MyPics' string is wrong here changed to "mypics"

Some more observations

  • 'my pics" is wrong, No Space allowed
  • 'my_pics" is wrong, No Special character allowed
  • 'mypics123' is correct, Numbers are allowed

Above rules will be applicable to other methods too like

GetQueueReference();
GetBlockBlobReference();