开发者

WCF Service Security Exception caused when trying to access data via LINQ to SQL

I'm currently in the beginning of learning WCF, as some of the concepts and the functionality they provide look interesting and also useful in a project I'm undertaking.

So far I've been following some pretty simple guides to get the hang of it but after creating my first host service I've come a bit unstuck, after trying to retrieve some data from a SQL Database and recieving the following error while using LINQ to SQL:

Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

I've had a look around and seen some suggestions as how to fix this, but non have seemed to be applicable as I'm creating a simple WCF service library purely for testing.

The code trips up on the following line:

me = aDb.Messages.ToList();

The project itself is held on a remote drive, but when I run to debug is run locally, however the database is a test server located again remotely. All the SQL credentials are correct as the connection tests succesfully and I've checked the connection string. Finally the service is running as a basicHttp Below you can see all my code so if you have any ideas as to how I can stop the error it would be appreciated.

namespace AnnouncementServiceLibrary
{
    [ServiceContract]
    public interface IConnect
    {
        [OperationContract]
        List<Mess> ConnectUser(string userId);
    }
}

namespace AnnouncementServiceLibrary
{
    public class AnnounceService : IAnnounceService
    {
#region IConnect Members

        public List<Mess> ConnectUser(string userId)
        {
                List<Mess> mess = new List<Mess>();
                List<Message> me;
                List<Mes开发者_开发技巧sageLink> messLink;

                AnnouncementDBDataContext aDb = new AnnouncementDBDataContext();

                me = aDb.Messages.ToList();
                messLink = aDb.MessageLinks.ToList();

                var result = (from a in messLink
                              join b in me
                                  on a.UniqueID equals b.UniqueID
                              where a.UserID == userId
                              select new { b.UniqueID, b.Author, b.Title, b.Body, b.Priority, a.Read, b.TimeRecieved }).
                    DefaultIfEmpty();

                foreach (var a in result)
                {
                    mess.Add(new Mess(a.UniqueID, a.Author, a.Title, a.Body, a.Priority, (bool)a.Read, a.TimeRecieved));
                }
                return mess;
        }
        #endregion
    }
}


This could all be tied back to the fact that your application is building from a network share. Take a look at this: http://blogs.msdn.com/shawnfa/archive/2003/06/20/57023.aspx

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜