none
Silverlight OOB + Silverlight-based WCF Service issue

    Question

  • I am trying to communicate with a database in Silverlight, and it has to be an OOB. But, so far I figured out the only way I could do it was from a webpage, since it's OOB it has to be done with a Web Service, to make things quite worse the database is MySQL (but I used the MySQL Connector, and seems to be going good so far). So, after all the trouble in the last couple days to find this all out I get the following error:

    "The remote server returned an error: NotFound."

    Do not know if it is because the project was originally without a web page, or what. The code is this one below in the Web Service:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    namespace SilverlightWCFTeste
    {
        public class Teste
        {
            public int ValeID { get; set; }
            public string ValeText { get; set; }
        }
    }
    using System;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.ServiceModel.Activation;
    using MySql.Data;
    using MySql.Data.MySqlClient;
    using System.Collections.Generic;
    using System.Data;
    
    namespace SilverlightWCFTeste
    {
        [ServiceContract(Namespace = "")]
        [SilverlightFaultBehavior]
        [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
        public class TesteService
        {
            [OperationContract]
            public List<Teste> TesteList(string query)
            {
                string nwConn = System.Configuration.ConfigurationManager.ConnectionStrings["ValeString"].ConnectionString;
                var testeList = new List<Teste>();
                using (MySqlConnection conn = new MySqlConnection(nwConn))
                {
                    conn.Open();
                    using (MySqlCommand cmd = new MySqlCommand(query, conn))
                    {
                        MySqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                        if (dr != null)
                            while (dr.Read())
                            {
                                var teste = new Teste
                                {
                                    ValeID = dr.GetInt16(0),
                                    ValeText = dr.GetString(0)
                                };
                                testeList.Add(teste);
                            }
                        return testeList;
                    }
                }
    
                // Add more operations here and mark them with [OperationContract]
            }
        }
    }

    And the mainpage on Silverlight code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using ValeDoRio.ServiceReferenceVale;
    
    namespace ValeDoRio
    {
        public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
                ServiceClient client = new ServiceClient();
                client.TesteListCompleted += new EventHandler<TesteListCompletedEventArgs>(client_TesteListCompleted);
                client.TesteListAsync(@"SELECT * FROM testando");
            }
    
            void client_TesteListCompleted(object sender, TesteListCompletedEventArgs e)
            {
                dataGrid1.ItemsSource = e.Result;
            }
        }
    }
    

    Can somebody, please, shed me some light? I am quite desperate to make this work!

    Att,
    Pedro Loures.
    Friday, April 27, 2012 1:26 PM

Answers

All replies

  • The Not Found error is just the general Silvelright "Something is wrong" error. If you try hitting your service directly using the browser or by watching what happens with Fiddler you may get more information on what the error is.

    That being said, this forums is for WCF RIA Services, not WCF in general. If you ask your question in the web services forum (http://social.msdn.microsoft.com/Forums/en-US/silverlightweb/threads//1?Accessing+Web+Services+with+Silverlight) then you may get a better, faster answer. You may still get answered here, but it might take longer.

    Friday, April 27, 2012 2:46 PM
  • Is there a tutorial on how Fiddle works?

    I get the idea that the error is when I send the query, and this is what I get when I try to get on the webservice through link:

    Server Error in '/WebSite1' Application.
    The type 'Service', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
    
    Exception Details: System.InvalidOperationException: The type 'Service', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.
    
    Source Error:
    
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
    
    Stack Trace:
    
    [InvalidOperationException: The type 'Service', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.]
       System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +51530
       System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +1461
       System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +44
       System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +651
    
    [ServiceActivationException: The service '/WebSite1/Service.svc' cannot be activated due to an exception during compilation.  The exception message is: The type 'Service', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found..]
       System.Runtime.AsyncResult.End(IAsyncResult result) +688590
       System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +190
       System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, String routeServiceVirtualPath, Boolean flowContext, Boolean ensureWFService) +234
       System.ServiceModel.Activation.HttpHandler.ProcessRequest(HttpContext context) +24
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +100
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
    
    Friday, April 27, 2012 3:33 PM
  • Hi,

    I reply the thread in another post as web services forum is the proper forum:

    http://social.msdn.microsoft.com/Forums/en-US/silverlightweb/thread/05b664e5-99f2-4662-8314-24a4766dc1df/

    Monday, April 30, 2012 3:44 AM