how to get the data from the sqlserver's table data in Silverlight using CAG

Topics: Prism v2 - Silverlight 2
Jul 6, 2009 at 2:45 PM
Edited Jul 6, 2009 at 2:49 PM

i implemented a WCF service to get the data from sql server table. i published and use the service reference in Silverlight sample. I'm getting some errors saying that
Error 3 The type name 'ServiceReference1' does not exist in the type 'HelloWorldModule.HelloWorldModule' C:\Documents and Settings\raviv\My Documents\CAGInfo\Prism.Source\Sour

ce\Quickstarts\Hello World\HelloWorld.Silverlight\HelloWorldModule\Service References\ServiceReference1\Reference.cs 133 76 HelloWorldModule

how to get the data from the sqlserver's table data in Silverlight using CAG.
 Without using CAG I'm getting the data by using WCF Service. By using reference i'm directly binding the list to item source of my control in xaml file. But using CAG it's not possible.

Can any one tell me how to achieve the data from database using CAG in SilverLight?

Jul 7, 2009 at 5:52 PM

Hi ravivellanky,  

There are several ways you can access SQL data from Silverlight. As you said, using a WCF web service might be a good option. Though Prism-v2 does not provide any special infrastructure to expose or consume web services, you should be able to use WCF as in any other Silverlight project.  

The error you mention is probably because of a naming conflict between the HelloWorldModule namespace and the HelloWorldModule class. The service proxy client generated by WCF (Reference.cs) uses full names, so it will generate for example HelloWorldModule.ServiceReference1.IService1 (trying to make reference to HelloWorldModule namespace) but it will fail compiling because this way is referencing an unexisting ServiceReference1 type inside the HelloWorldModule class.

To work around this issue you should do one of the following (in my personal preferred order):

1.       Refactor the solution to change the name of the HelloWorldModule class (you might need to change the prism module configuration).

2.       Refactor the solution changing the name of the HelloWorldModule namespace (you might also need to change the project name, the project's default namespace and any configuration referring that namespace).

3.       Modify the generated code removing the HelloWorldModule prefix (for example modify all HelloWorldModule.ServiceReference1.IService1 to ServiceReference1.IService1). The drawback of this approach is that any update to the service (using the Update Service Reference option) will undo your changes.

Once that compilation error is resolved, take into consideration the run-time error discussed in the following post: How-to: Consume WCF services from Composite Application Guidance for WPF and Silverlight(Prism-v2) Modules

There are some other discussions in the forum related to consuming web services in prism:

 Hope it helps!

 Matias Bonaventura

http://blogs.southworks.net/matiasb

Jul 10, 2009 at 10:02 AM
Edited Jul 10, 2009 at 11:30 AM

Bonaventura,

 

                     First of all, thanks for the reply. I'm still getting the same error after i renamed my class name of module name space. Yes it is initially HelloWorldModule namespace and the HelloWorldModule class. Now I changed the name of the class as HWMClass to module. 

While adding the servicereference to our module it is not showing in the ServiceReferences.ClientConfig file. I used traditional webservice to get the data frm the data base which is of .asmx extension. It works fine. But i wanted to be work with WCF service. Following is the error i'm getting while running the sample.

Could not find default endpoint element that references contract 'ServiceReference2.IService1' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.

 

Help me in this context.

Jul 10, 2009 at 7:24 PM

Hi ravivellanky, 

The following post shows a possible way to resolve the error you mention: How-to: Consume WCF services from Composite Application Guidance for WPF and Silverlight(Prism-v2) Modules 

Please let me know if this works in your scenario. 

Matias Bonaventura
http://blogs.southworks.net/matiasb

Jul 13, 2009 at 8:55 AM
Edited Jul 13, 2009 at 8:57 AM

You simply need to ensure that your ServiceReferences.ClientConfig exists in the Application project and you must manually copy all contents from each SL project that has one to this one. You could probably create a pre-build event to aggregate these for the solution on your behalf too.

I am using WCF from multiple modules and have had to do this one manual step for now.

Just in case, you also need to ensure that the wsHttpBinding on the server is changed to the basicHttpBinding (or something like that). I remember having some trouble with this originally.

HTH,
Fred

Jul 13, 2009 at 9:50 AM

Fred,

             While adding the servicereference to our module it is not showing in the ServiceReferences.ClientConfig file. I mean in .cilent config file the service is not configured. While building it's not showing any error. But while running the application that to when load the data in page load it is showing the following exception.

Could not find default endpoint element that references contract 'ServiceReference2.IService1' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.

 

-Ravi vellanki

 

 

 

Jul 14, 2009 at 4:39 AM

So in my project, I commented out the endpoint elements in my ServiceReferences.ClientConfig and replicated the exception you are quoting here. Can you elaborate on the project structure and where you are getting this.

You should have an Application SL project and a Module SL project. I assume you are trying to add a Service Reference to the module project and in that project, there should be created a ServiceReferences.ClientConfig, correct? If so, you should see the proper configuration for the service there. You must manually copy that configuration information to the ServiceReferences.ClientConfig of the Application SL project. That .ClientConfig in the application project probably does not already exist and so you may need to create it or copy from the module.

The Build Action should be Content and the Copy to Output Directory Copy Always.

From: ravivellanky [mailto:notifications@codeplex.com]
Sent: Monday, July 13, 2009 1:51 AM
To: fredhirschfeld@comcast.net
Subject: Re: how to get the data from the sqlserver's table data in Silverlight using CAG [CompositeWPF:61587]

From: ravivellanky

Fred,

While adding the servicereference to our module it is not showing in the ServiceReferences.ClientConfig file. I mean in .cilent config file the service is not configured. While building it's not showing any error. But while running the application that to when load the data in page load it is showing the following exception.

Could not find default endpoint element that references contract 'ServiceReference2.IService1' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.

-Ravi vellanki

Read the full discussion online.

To add a post to this discussion, reply to this email (CompositeWPF@discussions.codeplex.com)

To start a new discussion for this project, email CompositeWPF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com