Wednesday, December 1, 2010

Using Silverlight Init parameters to get the WCF Service url dynamically

http://www.c-sharpcorner.com/UploadFile/dpatra/InitParamsInSilverlight06302009024633AM/InitParamsInSilverlight.aspx

http://msdn.microsoft.com/en-us/library/cc189004(v=VS.95).aspx


Step 1 :
Configure the WCF Service URL at web.config file



   1:  <configuration>
   2:    <appSettings>
   3:      <add key="myWCFServiceUrl" value="http://SomeServer:55460/myWCFService.svc" />
   4:    </appSettings>
   5:  </configuration>

Step 2 :
Supply the configured URL as a initparameters Silverlight 



   1:  <form id="form1" runat="server" style="height:100%">
   2:      <div id="silverlightControlHost">
   3:          <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
   4:                <param name="InitParams" value='myWCFServiceUrlParameter= <% =ConfigurationManager.AppSettings["myWCFServiceUrl"].ToString()%> '/>
   5:            <param name="source" value="ClientBin/mySilverlight.xap"/>
   6:                <param name="onError" value="onSilverlightError" />
   7:                <param name="background" value="white" />
   8:                <param name="minRuntimeVersion" value="4.0.50826.0" />
   9:                <param name="autoUpgrade" value="true" />
  10:                <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.0" style="text-decoration:none">
  11:                     <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
  12:                </a>
  13:            </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
  14:      </form>

Step 3 :
Modify the app.xaml.cs file to read the init parameters



   1:  public static string myWCFServiceURL = "";
   2:          public App()
   3:          {
   4:              this.Startup += this.Application_Startup;
   5:              this.Exit += this.Application_Exit;
   6:              this.UnhandledException += this.Application_UnhandledException;
   7:   
   8:              InitializeComponent();
   9:          }
  10:   
  11:          private void Application_Startup(object sender, StartupEventArgs e)
  12:          {
  13:              if (e.InitParams.ContainsKey("myWCFServiceUrlParameter") && !string.IsNullOrEmpty(e.InitParams["myWCFServiceUrlParameter"]))
  14:                  myWCFServiceURL = e.InitParams["myWCFServiceUrlParameter"];
  15:              this.RootVisual = new MainPage();
  16:          }

Step 4 :
use the URL during the WCF Client creation in Silverlight



   1:  myWCFServiceClient = new myWCFServiceClient(new BasicHttpBinding(), new EndpointAddress(App.myWCFServiceURL));

Silverlight ClientBin is not updated

Check the below Settings along with permission to the "Client Bin" folder





MOSS 2007 BDC Search

Video : Extending Search Capabilities with Office SharePoint Search 2007

http://sharepointmagazine.net/series/everything-bdc


http://sharepointmagazine.net/articles/customizing-search-series-new-content-and-scope-from-a-bdc-application

http://blah.winsmarts.com/2007-4-SharePoint_2007__BDC_-_Enabling_Search_on_business_data.aspx


http://sanjaynarang.wordpress.com/2007/04/09/sharepoint-2007-moss-enterprise-search-and-bdc-resources/


http://mosssearchcoder.codeplex.com/


http://sharepointsearchserv.codeplex.com/


http://www.sharepoint-tips.com/2006/07/found-it-how-to-add-properties-to.html


http://blogs.msdn.com/b/uksharepoint/archive/2009/05/12/sharepoint-search-how-to-create-a-fully-functioning-search-center-part-2.aspx


http://spadvancedsearch.codeplex.com/


http://tqcblog.com/2007/10/creating-a-custom-advanced-search-box-in-moss-2007/


http://www.slideshare.net/CoreyRoth/presentations

Agile

Good PPTs on Agile are at 
http://www.slideshare.net/Siddhi/presentations

Tuesday, November 30, 2010

Enabling cross-domain calls on self-hosted WCF services

http://blogs.msdn.com/b/carlosfigueira/archive/2008/03/07/enabling-cross-domain-calls-for-silverlight-apps-on-self-hosted-web-services.aspx


http://blogs.msdn.com/b/carlosfigueira/archive/2010/07/25/enabling-cross-domain-calls-for-sl-apps-on-self-hosted-tcp-services.aspx


http://forums.silverlight.net/forums/p/113172/259067.aspx


Example which I tried, 


(Download)


WCF Service :

File Name : IService1.cs



   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Linq;
   4:  using System.Runtime.Serialization;
   5:  using System.ServiceModel;
   6:  using System.Text;
   7:  using System.IO;
   8:  using System.ServiceModel.Description;
   9:  using System.ServiceModel.Web;
  10:   
  11:  namespace ConsoleApplication1
  12:  {
  13:      [ServiceContract]
  14:      public interface IService1
  15:      {
  16:          [OperationContract]
  17:          string GetData(int value);
  18:   
  19:      }
  20:      [ServiceContract]
  21:      public interface IPolicyRetriever
  22:      {
  23:          [OperationContract, WebGet(UriTemplate = "/clientaccesspolicy.xml")]
  24:          Stream GetSilverlightPolicy();
  25:   
  26:          [OperationContract, WebGet(UriTemplate = "/crossdomain.xml")]
  27:          Stream GetFlashPolicy();
  28:      }
  29:      
  30:    }



File Name : Service1.cs



   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Linq;
   4:  using System.Runtime.Serialization;
   5:  using System.ServiceModel;
   6:  using System.Text;
   7:  using System.IO;
   8:  using System.ServiceModel.Description;
   9:  using System.ServiceModel.Web;
  10:   
  11:  namespace ConsoleApplication1
  12:  {
  13:      
  14:      public class Service1 : IService1, IPolicyRetriever
  15:      {
  16:          public string GetData(int value)
  17:          {
  18:              return string.Format("You entered: {0}", value);
  19:          }
  20:   
  21:          public Stream GetSilverlightPolicy()
  22:          {
  23:              string result = @"<?xml version=""1.0"" encoding=""utf-8""?> 
  24:  <access-policy> 
  25:      <cross-domain-access> 
  26:          <policy> 
  27:              <allow-from http-request-headers=""*""> 
  28:                  <domain uri=""*""/> 
  29:              </allow-from> 
  30:              <grant-to> 
  31:                <resource path=""/"" include-subpaths=""true""/>
  32:              </grant-to> 
  33:          </policy> 
  34:      </cross-domain-access> 
  35:  </access-policy>";
  36:              WebOperationContext.Current.OutgoingResponse.ContentType = "application/xml";
  37:              return new MemoryStream(Encoding.UTF8.GetBytes(result));
  38:          }
  39:   
  40:          public Stream GetFlashPolicy()
  41:          {
  42:              string result = @"<?xml version=""1.0""?>
  43:  <!DOCTYPE cross-domain-policy SYSTEM ""http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"">
  44:  <cross-domain-policy>
  45:      <allow-access-from domain=""*"" />
  46:  </cross-domain-policy>";
  47:   
  48:              WebOperationContext.Current.OutgoingResponse.ContentType = "application/xml";
  49:              return new MemoryStream(Encoding.UTF8.GetBytes(result));
  50:          }
  51:   
  52:         
  53:      }
  54:  }
File Name : Program.cs



   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Linq;
   4:  using System.Text;
   5:  using System.ServiceModel;
   6:  using System.IO;
   7:  using System.ServiceModel.Description;
   8:  using System.ServiceModel.Web;
   9:   
  10:  namespace ConsoleApplication1
  11:  {
  12:          class Program
  13:      {
  14:          static void Main(string[] args)
  15:          {
  16:              string baseAddressHttp = "http://" + Environment.MachineName + ":8090";
  17:   
  18:              ServiceHost host = new ServiceHost(typeof(Service1), new Uri(baseAddressHttp));
  19:              host.AddServiceEndpoint(typeof(IService1), new BasicHttpBinding(), "myService");
  20:              host.AddServiceEndpoint(typeof(IPolicyRetriever), new WebHttpBinding(), "").Behaviors.Add(new WebHttpBehavior());
  21:   
  22:              ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
  23:              smb.HttpGetEnabled = true;
  24:              host.Description.Behaviors.Add(smb);
  25:              
  26:              host.Open();
  27:              Console.WriteLine("Host opened at " + baseAddressHttp);
  28:              Console.Write("Press ENTER to close");
  29:              Console.ReadLine();
  30:              host.Close(); 
  31:          }
  32:      }
  33:  }

Silverlight Code
File Name : MainPage.xaml


   1:  <UserControl x:Class="SilverlightApplication1.MainPage"
   2:      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   3:      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   4:      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
   5:      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
   6:      mc:Ignorable="d"
   7:      d:DesignHeight="300" d:DesignWidth="400">
   8:   
   9:      <Grid x:Name="LayoutRoot" Background="White">
  10:          <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="72,40,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
  11:          <TextBox Height="23" HorizontalAlignment="Left" Margin="211,83,0,0" Name="textBox2" VerticalAlignment="Top" Width="120" />
  12:      </Grid>
  13:  </UserControl>

File Name : MainPage.xaml.cs



   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Linq;
   4:  using System.Net;
   5:  using System.Windows;
   6:  using System.Windows.Controls;
   7:  using System.Windows.Documents;
   8:  using System.Windows.Input;
   9:  using System.Windows.Media;
  10:  using System.Windows.Media.Animation;
  11:  using System.Windows.Shapes;
  12:   
  13:  namespace SilverlightApplication1
  14:  {
  15:      public partial class MainPage : UserControl
  16:      {
  17:          public MainPage()
  18:          {
  19:              InitializeComponent();
  20:          }
  21:   
  22:          private void button1_Click(object sender, RoutedEventArgs e)
  23:          {
  24:                  ServiceReference1.Service1Client sc = new ServiceReference1.Service1Client();
  25:                  sc.GetDataAsync(Int32.Parse(textBox2.Text));
  26:                  sc.GetDataCompleted += new EventHandler<ServiceReference1.GetDataCompletedEventArgs>(sc_GetDataCompleted);
  27:          }
  28:   
  29:          void sc_GetDataCompleted(object sender, ServiceReference1.GetDataCompletedEventArgs e)
  30:          {
  31:              textBox2.Text = e.Result; 
  32:          }
  33:      }
  34:  }

FileName : ServiceReferences.ClientConfig



   1:  <configuration>
   2:      <system.serviceModel>
   3:          <bindings>
   4:              <basicHttpBinding>
   5:                  <binding name="BasicHttpBinding_IService1" maxBufferSize="2147483647"
   6:                      maxReceivedMessageSize="2147483647">
   7:                      <security mode="None" />
   8:                  </binding>
   9:              </basicHttpBinding>
  10:          </bindings>
  11:          <client>
  12:              <endpoint address="http://win-cnzdnl3hxvy:8090/myService" binding="basicHttpBinding"
  13:                  bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
  14:                  name="BasicHttpBinding_IService1" />
  15:          </client>
  16:      </system.serviceModel>
  17:  </configuration>

M-V-VM

Best MVVM Training

Learning WPF M-V-VM

http://www.codeproject.com/KB/silverlight/RIATasks.aspx
from http://www.wpftutorial.net/MVVM.html




Monday, November 29, 2010

Tools found today

http://rachanathecreation.blogspot.com/2010/11/any-weblock.html


Sour code to HTML with CSS to use in the Blogs
http://www.manoli.net/csharpformat/

Ado.net Entity Framework

IIIntroduction

Videos



http://thedatafarm.com/main.aspx


Entity Framework vs LINQ to SQL



  • LINQ to SQL is the quick-and-easy way to do it. This means you will get going quicker, and deliver quicker if you are working on something smaller.
  • Entity Framework is the all-out, no-holds-barred way to do it. This means you will take more time up-front, develop slower, and have more flexibility if you are working on something larger.
Stored Procedures in Entity Framework