<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mohamed Ibrahim Mostafa&#039;s Blog &#187; Silverlight</title>
	<atom:link href="http://www.mohamedibrahim.net/blog/category/silverlight/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mohamedibrahim.net/blog</link>
	<description>Technical issues, problems, errors, findings &#38; resolutions covering Microsoft Dynamics CRM, software development, Microsoft .NET, C#, VB.NET, Commerce Server, Integration, E-Commerce, Scribe, Online shops and more general technology and consultancy posts.</description>
	<lastBuildDate>Tue, 24 Aug 2010 09:22:45 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Creating and Using Silverlight web.config app settings (Web.config Configuration Applicatioin Settings) or app.config application settings configuration file for Silverlight</title>
		<link>http://www.mohamedibrahim.net/blog/2010/01/27/creating-and-using-silverlight-app-settings-webconfig-configuration-applicatioin-settings-to-change-wcf-service-address-after-deployment-servicereferencesclientconfig-servicereferences-clientconfig/</link>
		<comments>http://www.mohamedibrahim.net/blog/2010/01/27/creating-and-using-silverlight-app-settings-webconfig-configuration-applicatioin-settings-to-change-wcf-service-address-after-deployment-servicereferencesclientconfig-servicereferences-clientconfig/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 21:47:30 +0000</pubDate>
		<dc:creator>Mohamed Ibrahim Mostafa</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[General Development]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Configuraiton]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[ServiceReferences.ClientConfig]]></category>
		<category><![CDATA[Settings]]></category>
		<category><![CDATA[xap]]></category>

		<guid isPermaLink="false">http://www.mohamedibrahim.net/blog/?p=149</guid>
		<description><![CDATA[Post Summary:
This posts explains how to create and use something similar to a silverlight  web.config, App.config and appsettings (or app settings) configuration file for silverlight application. This is based on re-using serviceReference.clientconfig as an appconfig configuration file.
The Problem:
A) configuration application settings (like the one in web.config, appsettings or app settings application configuration file):
This is probably very common. Your [...]]]></description>
			<content:encoded><![CDATA[<p><span style="text-decoration: underline;">Post Summary:</span></p>
<p>This posts explains how to create and use something similar to a silverlight  web.config, App.config and appsettings (or app settings) configuration file for silverlight application. This is based on re-using serviceReference.clientconfig as an appconfig configuration file.</p>
<p><span style="text-decoration: underline;">The Problem:</span></p>
<p><span style="text-decoration: underline;">A) configuration application settings (like the one in web.config, appsettings or app settings application configuration file):</span><br />
This is probably very common. Your silverlight application might well need to have some configuration settings that you can change their values without having to re-build and re-deploy the whole application because of a small change in a connection string or appSetting value. Again, AppSettings in good old web.config files in ASP.net applications were the best solution in this case.</p>
<p><span style="text-decoration: underline;">B) WCF Address (EndPoint address value) change after building:</span><br />
Another reason for wanting to have a configuration file in a silverlight application: Have you ever wanted to change the WCF service address (endpoint address) in your silverlight application after deployment. Imagine that you built a silverlight application and deployed it on your test server. The application was tested and confirmed issues and bug free. Now you want to re-deploy the application to the Live server but the WCF service address (end point address) is different which is probably quite common. It might also be that the address is the same but the port on which the WCF service is listening is different. In this case, you will need to change the value of the WCF endpoint address and re-build. So what happened to configuration files! They are a standard now in all Microsoft environments. </p>
<p><span style="text-decoration: underline;">Problem Summary:</span> The problem is there is no clear web.config file in silverlight as the whole code is compiled into a (.xap) file which any html or aspx page can call.</p>
<p><span style="text-decoration: underline;">Solution:</span></p>
<p>In my silverlight application, I had a connection string value that I need to use in my silverlight application (pass it to the webservice). Hence, I wanted the flexibility to change the WCF endpoint address and the connection string configuration value (or any other application setting). I started looking for a solution but I found that most work arounds were either two long or too complicated. As always, I like simple things and I don&#8217;t like over complications. I have to say though that most if not all work arounds that I found were useful for me to come up with this solution. I am not sure but I believe (and hope) the following solution is unique as I have searched for quite a while to find anyone suggesting this idea but I couldn&#8217;t find any.</p>
<p><strong><span style="text-decoration: underline;">Solution part 1</span>: The simplest way for adding application settings to a silverlight application.</strong></p>
<p>Now since ServiceReferences.ClientConfig is just an xml configuration file, you can actually edit it in visual studio and simply add your application settings.</p>
<p>Your file will look something like this:</p>
<pre>&lt;configuration&gt;
    &lt;system.serviceModel&gt;
        &lt;bindings&gt;
            &lt;basicHttpBinding&gt;
                &lt;binding name="xrmServiceBasicHttp" maxBufferSize="2147483647"
                    maxReceivedMessageSize="2147483647"&gt;
                    &lt;security mode="None"&gt;
                        &lt;transport&gt;
                            &lt;extendedProtectionPolicy policyEnforcement="Never" /&gt;
                        &lt;/transport&gt;
                    &lt;/security&gt;
                &lt;/binding&gt;
            &lt;/basicHttpBinding&gt;
        &lt;/bindings&gt;
        &lt;client&gt;
            &lt;endpoint address="<a href="http://localhost:1234/MyWCFService.svc">http://localhost:1234/MyWCFService.svc</a>" binding="basicHttpBinding"
                bindingConfiguration="xrmServiceBasicHttp" contract="XrmService.IXrmService"
                name="xrmServiceBasicHttp" /&gt;
        &lt;/client&gt;
    &lt;/system.serviceModel&gt;</pre>
<pre><strong>  &lt;appSettings&gt;
    &lt;add key="ConnectionString" value="data source=ABC01;initial catalog=DB01;integrated security=SSPI;persist security info=False;packet size=4096" /&gt;
  &lt;/appSettings&gt;</strong></pre>
<pre>&lt;/configuration&gt;</pre>
<p>Now that you have added your application setting (connection string) to your ServiceReferences.ClientConfig, you need to use it in your silverlight code behind (.xaml.cs) file.</p>
<p>Remember, ServiceReferences.ClientConfig is just an XML file (already said that many times!). Hence, you can write a very simple and straight forward function that parses your ServiceReferences.ClientConfig xml file and returns the appSetting value of your application setting.<br />
A function to return an AppSetting value from your clientconfig file can look something like this:</p>
<pre>private string getAppSetting(string strKey)
        {
            string strValue = string.Empty;
            XmlReaderSettings settings = new XmlReaderSettings();           
            settings.XmlResolver = new XmlXapResolver();
            XmlReader reader = XmlReader.Create("ServiceReferences.ClientConfig");
            reader.MoveToContent();
            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element &amp;&amp; reader.Name == "add")
                {
                    if (reader.HasAttributes)
                    {
                        strValue = reader.GetAttribute("key");
                        if (!string.IsNullOrEmpty(strValue) &amp;&amp; strValue == strKey)
                        {
                            strValue = reader.GetAttribute("value");
                            return strValue;
                        }
                    }
                }
            }
            return strValue;</pre>
<pre>        }
Finally in your code, to retrieve the AppSetting value for the appSetting key (ConnectionString) that you created, you can just call the above function like this:</pre>
<p>client.SetConnectionStringAsync(getAppSetting(&#8220;ConnectionString&#8221;));<br />
And One last thing, remember when you create the WCF service client object, don&#8217;t explicitly call the WCF service address, as it is already in your ClientConfig file.</p>
<p>So, just call the end Point Configuration Name (endPointConfigurationName) that you want to use. Just like this:</p>
<p>MyServiceClient client = new MyServiceClient(&#8220;MyServiceBasicHttp&#8221;);</p>
<p>&#8212;&#8212;&#8212;-</p>
<p><strong><span style="text-decoration: underline;">Solution part 2:</span> Changing WCF address and endpoint values in &#8220;ServiceReferences.ClientConfig&#8221;.</strong></p>
<p>Anyway, the first thing we need to do is to understand that &#8220;ServiceReferences.ClientConfig&#8221; that all silverlight applications have and use if they are connecting to a WCF sercvice, is just a simple XML file. Actually, not only an XML file but also a configuration file for the application.</p>
<p>You also need to know that the silverlight xap (*.xap) file that silverlight generates is a simple compressed (zipped) file. For this reason, you actually can rename the file to (something.zip) from (something.xap) and then you can access its content. The content of the xap file includes AppManifes.xaml, your application dlls and most importantly &#8220;ServiceReferences.ClientConfig&#8221;.</p>
<p>Now, when I tried to unzip it, change the content of one of its files and then re-zip it and rename it back to (something.xap), this has corrupted it. My application failed. I am not sure why. This was the case despite the fact that most posts about unpacking, unzipping and re-packaging the .xap file works.</p>
<p>What actually works is the following:<br />
Rename the something.xap file to something.zip file. Open the zip file without unzipping (just double click on it) and then copy the file you want to edit, which in our case is the &#8220;ServiceReferences.ClientConfig&#8221; and paste it in a different location. Edit it and make all the changes you need to it and then copy it and paste back into the something.zip file. Replace the exisitng file there. Now go to something.zip and rename it back to something.xap.</p>
<p>Whatever change you have made should now work.</p>
<p>&#8212;&#8212;&#8212;&#8211;</p>
<p>I hope this helps. I really think it is an effective way to get your AppSetting values.</p>
<p>If you got any questions, please comment below (Kindly don&#8217;t use the contact page for questions on posts please)</p>
<p>Also, please let me know (via a comment below) if you want a copy of this application code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mohamedibrahim.net/blog/2010/01/27/creating-and-using-silverlight-app-settings-webconfig-configuration-applicatioin-settings-to-change-wcf-service-address-after-deployment-servicereferencesclientconfig-servicereferences-clientconfig/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Introduction and Notes about WCF, Silverlight and Creating a Silverlight application that consumes &#8211; invokes a WCF service via async (asynchronous) web service call</title>
		<link>http://www.mohamedibrahim.net/blog/2009/11/03/introduction-notes-about-wcf-silverlight-and-creating-a-silverlight-application-that-consumes-invokes-a-wcf-service-via-async-asynchronous-web-service-call/</link>
		<comments>http://www.mohamedibrahim.net/blog/2009/11/03/introduction-notes-about-wcf-silverlight-and-creating-a-silverlight-application-that-consumes-invokes-a-wcf-service-via-async-asynchronous-web-service-call/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 19:31:00 +0000</pubDate>
		<dc:creator>Mohamed Ibrahim Mostafa</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Web Service]]></category>

		<guid isPermaLink="false">http://www.mohamedibrahim.net/blog/?p=132</guid>
		<description><![CDATA[This post is an introduction and a collection of some useful information, notes and facts about WCF in genreal, Silverlight and running a silverlight web application that uses a WCF service via asynchronous web service call.
- The first fact that you need to know is that:
The only option for web service calling in Silverlight is [...]]]></description>
			<content:encoded><![CDATA[<p>This post is an introduction and a collection of some useful information, notes and facts about WCF in genreal, Silverlight and running a silverlight web application that uses a WCF service via asynchronous web service call.</p>
<p>- The first fact that you need to know is that:</p>
<p>The only option for web service calling in Silverlight is asynchronous and Silverlight framework does not provide any API for synchronous call. Saying that, there are few work arounds for synchronous web service calls from silverlight to a WCF service. Personally, I haven&#8217;t tried or need to use any of these. If you are interested, you can look at one of these posts:<br />
 * <a href="http://weblogs.asp.net/razan/archive/2010/01/14/emulating-synchronous-web-service-call-in-silverlight.aspx">http://weblogs.asp.net/razan/archive/2010/01/14/emulating-synchronous-web-service-call-in-silverlight.aspx</a><br />
 * <a href="http://marcgravell.blogspot.com/2009/02/async-without-pain.html">http://marcgravell.blogspot.com/2009/02/async-without-pain.html</a><br />
 * <a href="http://petesbloggerama.blogspot.com/2008/07/omg-silverlight-asynchronous-is-evil.html">http://petesbloggerama.blogspot.com/2008/07/omg-silverlight-asynchronous-is-evil.html</a><br />
- The greatest advantage of calling methods asynchronously is because it enables the application to continue doing useful work while the method call runs. If there is any delay from the WCF service in sending back the required data, Async calls ensures that your client application is not hanging there freezing and doing nothing until the Windows Communication Foundation (WCF) services returns the requried data. WCF and clients can participate in asynchronous operation calls at two distinct and different levels of the application. This makes WCF applications flexibile to maximize throughput balanced against interactivity.</p>
<p>- Visual Studio .NET 2008 gives you two project templates to create a WCF project:<br />
 1- &#8220;WCF Service Application&#8221; and<br />
 2- &#8220;WCF Service Library.&#8221;</p>
<p>WCF Service Application is the conventional web service application similar to ASP.NET web service but in this case built on Windows Communication Foudnation technology.</p>
<p>WCF Service Library project is different. The output of this project is a compiled dll file(s) along with a dll.config configuration file. The produced output can then be added to a client service application or project, deployed as a separated secure web service or as part of a larger hosted web service.</p>
<p>- When creating a WCF service for a silverlight application, you can simply add the WCF service to the test Web project which is added by default by Visual Studio when you create a new Silverlight 3 project. You can do this by right clicking on the silverlight web project (test project usually called .Web) and then click on add new item. In the new item window, always choose in this case silverlight enabled WCF service as this adds one line to your web.config. On the other hand, you can add the WCF service as another project to the same solution or even a separate solution which is the more practical approach as normally the web service is separate and hosted independantly from its client(s).</p>
<p>- If the WCF client application is not silverlight, opt to use the asynchronous approach in your operation implementation especially in the case when the service implementation makes a blocking call, such as doing Input/Output IO work.</p>
<p>Generally, even if you have a choice to choose between a synchronous and asynchronous call, always try to opt for the asynchronous one.</p>
<p>MSDN (and Microsoft) specifies the essential cases that you need to use Asynchornous calls to WCF as follows:</p>
<p>* If it is a silverlight application (the only option you have really!).</p>
<p>* If you are invoking operations from a middle-tier application.</p>
<p>* If you are invoking operations within an ASP.NET page, use asynchronous pages.</p>
<p>*- If you are invoking operations from any application that is single threaded, such as Windows Forms or Windows Presentation Foundation (WPF).</p>
<p>In all these cases, always try to opt to Async calls rather than synchronous if this is an option.<br />
- WCF is Microsoft&#8217;s attempt of unifying web and distributed services. WCF services can work with a variety of client applications including php, ruby, etc. and any client that can use basicHTTP binding.</p>
<p>- WCF is regarded as the successor to conventional Microsoft web services and communication technologies such as: DDL, DCOM, Remoting, Web Services, WSE, etc.. This is especially because WCF is built with the aim to provide &#8220;SOA&#8221; or Service Oriented Architecture for distributed applications.</p>
<p>- WCF can have messages sent in a variety of channels including HTTP, TCP, MSMQ, Named pipe, etc.</p>
<p>- WCF runtime resides under the System.ServiceModel namespace.</p>
<p>- In most cases WCF has a much better and faster performance ranging between 25%-50% in some cases. Refer to this MSDN article for some comparisons: <a href="http://msdn.microsoft.com/en-us/library/bb310550.aspx">http://msdn.microsoft.com/en-us/library/bb310550.aspx</a></p>
<p>- The throughput of WCF is inherently scalable from a single processor to a quad processor.</p>
<p>- The WCF model unifies the feature wealth of ASMX, WSE, Enterprise Services, MSMQ, and Remoting. This way, developers only have to master a single programming model.</p>
<p>- WCF can be hosted in IIS Servers, Windows services and standalone apps like windows forms, console apps.</p>
<p>- WCF provides a DataContractSerializer which allows complex data types and private attributes to be serialized and sent. Being Serializable means, the object can be hydrated, dehydradted from a stream/bunch of bytes, into a living class instance.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mohamedibrahim.net/blog/2009/11/03/introduction-notes-about-wcf-silverlight-and-creating-a-silverlight-application-that-consumes-invokes-a-wcf-service-via-async-asynchronous-web-service-call/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
