开发者

The remote server returned an error: NotFound

I am using MVVM pattern for Silverlight.

I have these projects:

MVVMDemo.Data (Ria services link set to MVVMDemo.Data.Web) MVVMDemo.Data.Web (Contains all RIA services) MVVMDemo.Data.ViewModels MVVMDemo.Data.Models MVVMDemo (contains all views) MVVMDemo.Data.Common (contains all interfaces)

This is my RIA services class:

namespace MVVMDemo.Data.Web
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Data;
    using System.Linq;
    using System.ServiceModel.DomainServices.EntityFramework;
    using System.ServiceModel.DomainServices.Hosting;
    using System.ServiceModel.DomainServices.Server;



    [EnableClientAccess()]
    public class UserServices : LinqToEntitiesDomainService<IssueVisionEntities>
    {

        public IQueryable<User> GetUsersByLimit(int skip , int take)
        {
            return this.ObjectContext.Users.Skip(skip).Take(take);
        }

        public IQueryable<User> GetUsers()
        {
            return this.ObjectContext.Users;
        }

        public void InsertUser(User user)
        {
            if ((user.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(user, EntityState.Added);
            }
            else
            {
                this.ObjectContext.Users.AddObject(user);
            }
        }

        public void UpdateUser(User currentUser)
        {
            this.ObjectContext.Users.AttachAsModified(currentUser, this.ChangeSet.GetOriginal(currentUser));
        }

        public void DeleteUser(User user)
        {
            if ((user.EntityState == EntityState.Detached))
            {
                this.ObjectContext.Users.Attach(user);
            }
            this.ObjectContext.Users.DeleteObject(user);
        }
    }
}

This is my model which calls RIA services :-

namespace MVVMDemo.Models
{
    [Export(typeof(IUserModel))]
    public class UserModel : IUserModel
    {
        private const int PAGESIZE = 10;
        private int skip = 0;


        private UserServices _context;
        private UserServices Context
        {
            get
            {
                if (_context == null)
                {
                    _context = new UserServices();
                }
                return _context;
            }
        }

        public void GetAllUsersAysnc()
        {
            PerformQuery<User>(Context.GetUsersQuery(), GetAllUsersAsyncComplete);
        }

        private void PerformQuery<T>(EntityQuery<T> query , EventHandler<EntityResultArgs<T>> eventHandler) where T:Entity
        {
            this.Context.Load<T>(query, LoadBehavior.RefreshCurrent, r =>
            {
                if (eventHandler != null)
                {
                    try
                    {
                        if (r.HasError)
                        {
                            eventHandler(this, new EntityResultArgs<T>(r.Error));
                            r.MarkErrorAsHandled();
                        }
                        else
                            eventHandler(this, new EntityResultArgs<T>(r.Entities));
                    }
                    catch (Exception ex)
                    {
                        eventHandler(this, new EntityResultArgs<T>(ex));
                    }

                }
            },null);
        }

        public event EventHandler<EntityResultArgs<Data.Web.User>> GetAllUsersAsyncComplete;

        public void GetAllUsersByLimit()
        {
            PerformQuery<User>(Context.GetUsersByLimitQuery(skip,PAGESIZE), GetAllUsersByLimitAsyncComplete);
        }

        public event EventHandler<EntityResultArgs<Data.Web.User>> GetAllUsersByLimitAsyncComplete;
    }

Whenever i run the method GetAllUsersAysnc i always get this error :-

http://img408.imageshack.us/img408/6150/62968542.jpg

This is 开发者_高级运维my app.config in MVVMDemo.Data.Web

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <add name="DomainServiceModule" preCondition="managedHandler"
        type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </modules>
    <validation validateIntegratedModeConfiguration="false" />

  </system.webServer>
  <connectionStrings>
    <add name="IssueVisionEntities" connectionString="metadata=res://*/IssueVisionModel.csdl|res://*/IssueVisionModel.ssdl|res://*/IssueVisionModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=TAPESH\MSSQLSERVER2008;Initial Catalog=IssueVision;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
      multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

  <system.web>    
    <httpModules>
      <add name="DomainServiceModule" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </httpModules>
  </system.web>


</configuration>

And this is my web.config of Asp.Net website which is hosting the silverlight application

<?xml version="1.0"?>

<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />

    </system.web>

</configuration>

I have no idea what is happening and I am a beginner in RIA services.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜