views:

91

answers:

2

I've been looking for this answer, and all I found was this link, but when I attempted to follow the tutorial I failed hard. What I need is to connect my Silverlight application to a database, just to show informations from a specific table. As I don't want to use the same ORM for my page and my silverlight app, I created a new WCF webservice project, and created my LINQ to SQL classes inside of it.

I tested my WCF service and it works fine, but somehow my Silverlight App doesnt reach it. I've changed the web.config file, and now it looks as follows.

My web.config

<?xml version="1.0"?> <configuration>

  <connectionStrings>
    <add name="bd_webportosConnectionString" connectionString="Data Source=BARNEY\DEV;Initial Catalog=bd_webportos;User ID=sa;Password=Stigeo_1_adm_1"
      providerName="System.Data.SqlClient" />   </connectionStrings>   <system.web>
    <compilation debug="true" targetFramework="4.0" />   </system.web>   <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="basicHttpBindingConfig">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Ntlm"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:7298/DataToSilverlight.svc"
          binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
          contract="DataRetrieverReference.IService1" name="BasicHttpBinding_IService1" />
    </client>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information
-->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />  </system.serviceModel>  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/> </system.webServer>    </configuration>

I don't know how to solve this problem. And although I got stuck, I tried to keep going forward, but then I got stuck again in the next step, that was to add the service reference to my silverlight app. As I try to do what it says, the following message is shown:

There was an error downloading metadata from the address. Please verify that you have entered a valid address.

I tested the service through WCF Test Client, and it worked, but my silverlight app doesn't reach it. I get the following exception:

An error occurred while trying to make a request to URI 'http://localhost:7298/DataToSilverlight.svc'. This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services. You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent. This error may also be caused by using internal types in the web service proxy without using the InternalsVisibleToAttribute attribute. Please see the inner exception for more details.

Can you guys help me solving this big problem, or even showing another way to achieve what I want?

I also recently discovered that my crossdomain.xml doesn't get loaded ... but I don't know what that means.

A: 

According to MSDN the <services> tag should be inside your <system.serviceModel> tag. Just copy the whole block in there.

Edit: About the connect to database part.

Silverlight can not magically "query" the database through the WCF service unless you create a WCF Data Service/OData. To get data from the database to your Silverlight client in a straight forward way you need to create methods in the WCF service that queries the database according to the in-parameters of the WCF method, packs it up i a suitable data structure (List<Customer> in the example in you link) and returns the result to the Silverlight client.

The error you get "There was an error downloading metadata from the address. Please verify that you have entered a valid address." is not an error relevant to the database, it is an error telling that your WCF service can not be found. That would have happened regardless if your WCF service used a database or not.

It looks like there might be further configuration errors in the WCF service, that might explain why the reference to the service can not be added. How does your dialog corresponding to "Figure 3-13. Adding a reference to the Web Service" look like? You can edit your question and insert a screen dump.

Albin Sunnanbo
This solves the first part, I guess, but the second part of my question still unanswered. I never worked with this kind of thing before and I'm a little confused about this. Why do you say it has nothing to do with database, if its a way of linking them?
Bruno
@Bruno: The error has nothing to do with your database, you would have got the error regardless if you had a database or not. I edited my answer with more details. You may also try to start your project and see if there are any errors relating to the web.config or something else related to your service.
Albin Sunnanbo
The thing that seems to confuse you is the role of WCF. WCF is not just a database interface, it is more of a general purpose service/server. It can be used for many things. Reading data from a database is just one thing out of many you can do with a WCF service.
Albin Sunnanbo
A: 

You can try this way :

http://www.dotnetspider.com/tutorials/Silverlight-Tutorial-315.aspx

Simple and easy.

Swapnil Gupta
I've done this way, but it didn't work. My method that get the database info doesn't reach my handler. Also, the code is slightly different:webService.GetDataCompleted += new EventHandler<DataRetrieverReference.GetDataCompletedEventArgs>(webService_GetDataCompleted);
Bruno
for your sake i hope you are not forgetting to add the following line below the initialisation of the event:webService.GetDataASync();
Sam
I didn't forget it.
Bruno