This project is read-only.

Drop Down Populate using Cairngorm Framework

Feb 11, 2009 at 2:07 PM
Hi Modesty,

                How are you?.i have tried to populate drop down values from webservice usng cairngorm framework.I could not able to bind the values to drop down.Please can you tell me the sample code .

Thanks,
Mansoor
Feb 11, 2009 at 5:17 PM
Mansoor,

The "drop down" derives from ItemsControl, you can data bind it's ItemSource property to a collection property in Model. You can download sample code from http://www.codeplex.com/SilverlightCairngorm/Release/ProjectReleases.aspx?ReleaseId=18296, in the SilverlightCairngormDemo project, look at View/PhotoList.xaml, it's ItemSource is bound to PhotoList. PhotoList is defined in ModelLocator, whenever a webservice call returns (in SearchPhotoCommand), it uses LINQ to rebuild the collection based on the XML returned from service.

Good luck and Have fun.
Feb 13, 2009 at 12:43 PM
Hi Modesty,

                Thanks for ur code.it really worked well.I have some more issues.can u please tell me how to invoke a webservice dynamically by passing url.

 have written a wrapper class in console application.it works well.But i am not able to integrate into silverlight application mainly with in cairngorm frameowrk.I will paste the code here.Please tell me how to proceed further.


using

System;

 

using

System.CodeDom;

 

using

System.CodeDom.Compiler;

 

using

System.Security.Permissions;

 

using

System.Web.Services;

 

using

System.Web.Services.Description;

 

using

System.Web.Services.Discovery;

 

using

System.Xml;

 

using

System.Xml.Serialization;

 

using

System.Reflection;

 

using

System.Collections.Specialized;

 

using

System.Collections.Generic;

 

using

System.Collections;

 

using

System.IO;

 

using

System.Net;

 

using

System.Web;

 

using

System.Web.Services.Protocols;

 

 

namespace

ConsoleApplication1

 

{

 

class Program

 

{

[

SecurityPermissionAttribute(SecurityAction.Demand, Unrestricted = true)]

 

 

static void Main(string[] args)

 

{

DynamicInvocation();

}

 

 

private static void DynamicInvocation()

 

{

 

 

//try

 

 

//{

 

 

XmlDocument xmlDoc = new XmlDocument();

 

xmlDoc.Load(

@"C:\\Connectionstring1.xml");

 

 

XmlNode xn = xmlDoc.SelectSingleNode("servicesettings");

 

 

String connstr = string.Empty;

 

connstr = xn.InnerText;

 

 

//Uri uri = new Uri("http://192.168.1.26/website3/Hrservice.asmx?wsdl");

 

 

Uri uri = new Uri(connstr);

 

 

WebRequest webRequest = WebRequest.Create(uri);

 

webRequest.Credentials = System.Net.

CredentialCache.DefaultCredentials;

 

 

//webRequest.Credentials = new NetworkCredential("patelronakp@yahoo.com", "lovely");

 

System.IO.

Stream requestStream = webRequest.GetResponse().GetResponseStream();

 

 

// Get a WSDL file describing a service

 

 

ServiceDescription sd = ServiceDescription.Read(requestStream);

 

 

string sdName = sd.Services[0].Name;

 

 

// Add in tree view

 

 

 

// Initialize a service description servImport

 

 

ServiceDescriptionImporter servImport = new ServiceDescriptionImporter();

 

servImport.AddServiceDescription(sd,

String.Empty, String.Empty);

 

servImport.ProtocolName =

"Soap";

 

servImport.CodeGenerationOptions =

CodeGenerationOptions.GenerateProperties;

 

 

 

CodeNamespace nameSpace = new CodeNamespace();

 

 

CodeCompileUnit codeCompileUnit = new CodeCompileUnit();

 

codeCompileUnit.Namespaces.Add(nameSpace);

 

// Set Warnings

 

 

ServiceDescriptionImportWarnings warnings = servImport.Import(nameSpace, codeCompileUnit);

 

 

if (warnings == 0)

 

{

 

StringWriter stringWriter = new StringWriter(System.Globalization.CultureInfo.CurrentCulture);

 

Microsoft.CSharp.

CSharpCodeProvider prov = new Microsoft.CSharp.CSharpCodeProvider();

 

prov.GenerateCodeFromNamespace(nameSpace, stringWriter,

new CodeGeneratorOptions());

 

 

// Compile the assembly with the appropriate references

 

 

string[] assemblyReferences = new string[2] { "System.Web.Services.dll", "System.Xml.dll" };

 

 

CompilerParameters param = new CompilerParameters(assemblyReferences);

 

param.GenerateExecutable =

false;

 

param.GenerateInMemory =

true;

 

param.TreatWarningsAsErrors =

false;

 

param.WarningLevel = 4;

 

CompilerResults results = new CompilerResults(new TempFileCollection());

 

results = prov.CompileAssemblyFromDom(param, codeCompileUnit);

 

Assembly assembly = results.CompiledAssembly;

 

 

Type service;

 

service = assembly.GetType(sdName);

 

foreach (Type type in assembly.GetTypes())

 

{

 

if (type.IsClass == true && type.Name.Contains("HRService"))

 

{

 

object ClassObj = Activator.CreateInstance(type);

 

 

MethodInfo objMethodInfo = type.GetMethod("Retrieve");

 

 

ParameterInfo[] paramInfo = objMethodInfo.GetParameters();

 

 

object[] args = new object[paramInfo.Length];

 

 

Dictionary<string, object> d = new Dictionary<string, object>();

 

d.Add(

"argument1", 1);

 

d.Add(

"argument2", String.Empty);

 

d.Add(

"argument3", 1);

 

d.Add(

"argument4", "F");

 

d.Add(

"argument5", 1);

 

d.Add(

"argument6", 0);

 

d.Add(

"argument7", 100);

 

 

string json = Newtonsoft.Json.JsonConvert.SerializeObject(d);

 

 

object[] str = { 1, "BurdenCategoriesService", "GetBurdenCategoriesGridPage", json, "" };

 

 

SoapHttpClientProtocol webProxy = (SoapHttpClientProtocol)ClassObj;

 

webProxy.PreAuthenticate =

true;

 

webProxy.UseDefaultCredentials =

true;

 

 

object objResult = objMethodInfo.Invoke(webProxy, str);

 

}

}

  

}

  

}

  

}

}







Please tell me how to proceed further.
I want to place this wrapper in silverlightdemo project , so that i can call this wrapper to invoke webservice from delegate(business)

Thanks,

Mansoor

Feb 16, 2009 at 2:53 AM
Mansoor,

You may have to change your code before trying to integrate into Cairngorm. First of all, Silverlight application is partially trusted, which means the SecurityPermissionAttribute(SecurityAction.Demand, Unrestricted = true)]  won't apply at all. Second, Silverlight application does NOT have access to file system (except isolated storage), so C:\\Connectionstring1.xml can't be read at all. And last, if your service are SOAP based, it's better to "Add Service Reference" fom Silverlight application, let visual studio generate the proxy for you, then you can reference them in Delegates.

Good luck and Have fun.