referencing the LinqToTwitter.dll from a WCF project

Sep 9, 2011 at 11:43 AM

Hi All,

I am creating a service, that is basically querying the LinqToTwitter.dll and returning results.  So at the moment I have the following :-

 

        public ObservableCollection<UserTweet> QueryUserTimeline(string strScreenName)
{
ObservableCollection<UserTweet> _userTweets = new ObservableCollection<UserTweet>();
            //do query ..................


}
return _userTweets;
}
Quite a simple method.  However when I run this, it is telling me that it is not finding the LinqToTwitter.dll.  I have included it as a reference and in the bin folder.
So I created a class library and did the exact same thing, and when I query the Class Library, it works fine.  So the problem is to call the dll from the WCF Service.
So my question is, is it possible to reference the LinqToTwitter.dll from a WCF Service Application?
Coordinator
Sep 9, 2011 at 5:11 PM
Edited Sep 9, 2011 at 5:12 PM

Hi,

I think it should work okay, unless you've found a scenario that doesn't work.  Try this:

1. Select References, Add NuGet Package.
2. Type LiNQ to Twitter in the search box.
3. Click the Intall button by LINQ to Twitter (Accept License and close).
4. Modified GetData, like this:
        public string GetData(int value)
        {
            var twitterCtx = new TwitterContext();

            var tweets =
                (from tweet in twitterCtx.Status
                 where tweet.Type == StatusType.Public
                 select tweet)
                .ToList();

            return string.Format("Tweet Count: {0}", tweets.Count);
        }
5. Add new console application project to solution.
6. Modify console project Main method, like this:
        static void Main(string[] args)
        {
            ServiceReference1.Service1Client svcClient = new ServiceReference1.Service1Client();

            string result = svcClient.GetData(0);

            Console.WriteLine(result);
            Console.ReadKey();
        }
7. Output:  "Tweet Count: 20"

This worked for me.  What's different about what you're doing?  Steps to repro would be helpful.

@JoeMayo

Sep 9, 2011 at 6:32 PM

Hi JoeMayo

I followed steps 1-4, however when compiling the project (WCF) I got this message 

Error 1 The type or namespace name 'LinqToTwitter' could not be found (are you missing a using directive or an assembly reference?) C:\RecentProjects\WPFTwitter\TwitterWCF\Service1.cs

I have the using LinqToTwitter clause and in the references I have LinqToTwitter

Coordinator
Sep 9, 2011 at 11:43 PM

My entire service implementation looks like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using LinqToTwitter;

namespace L2TWcfService
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    public class Service1 : IService1
    {
        public string GetData(int value)
        {
            var twitterCtx = new TwitterContext();

            var tweets =
                (from tweet in twitterCtx.Status
                 where tweet.Type == StatusType.Public
                 select tweet)
                .ToList();

            return string.Format("Tweet Count: {0}", tweets.Count);
        }

        public CompositeType GetDataUsingDataContract(CompositeType composite)
        {
            if (composite == null)
            {
                throw new ArgumentNullException("composite");
            }
            if (composite.BoolValue)
            {
                composite.StringValue += "Suffix";
            }
            return composite;
        }
    }
}

Do you have using declarations for both LinqToTwitter and System.Linq?  I'm also wondering if there's a missing dependency. i.e. L2T supports MVC 3 which is either a separate download or IIRC, installed with VS 2010 SP1.

Joe

Sep 11, 2011 at 5:13 PM

Hi Joe

I installed MVC3 and VS2010 SP1 but still getting the same error.

 

Can you send me your solution to test it?

Thanks

Sep 11, 2011 at 5:31 PM

I tried to add the 4.0Binaries for Silverlight instead, which is LinqToTwitterAg.dll, and that compiles correctly.  But at runtime, when I try to call the TwitterContext, I get the following error:-

 

Could not load file or assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified.

Coordinator
Sep 11, 2011 at 8:29 PM

I just created a new Samples page, accessible via the main page that has a downloadable WCF demo that I describe here.  BTW, the LinqToTwitterAg.dll is for Silverlight only.  You'll need to reference LinqToTwitter.dll.

Joe

Sep 12, 2011 at 8:10 AM

Hi Joe

Just wanted to let you know that your sample worked.  I guess my mistake was trying to add a WCF Service Library instead of a normal C# Library since I noticed that you have more referenced dll's that I had in my project.

So I can build on that now

Thanks a lot for your help