从WCF服务调用dll

时间:2011-09-08 11:46:55

标签: c# wcf wcf-data-services

我创建了一个模型,其中包含所有类和方法,现在我想从WCF服务中调用这些方法。

但是,当我引用Model dll并尝试返回对象列表时,我收到以下错误: -

  

找不到类型或命名空间名称'myModel'(您是否缺少using指令或程序集引用?)

是否可以从WCF Web服务调用dll?我做错了吗?

我在服务中的代码非常基本

using myModel;

然后: -

public ObservableCollection<myObject> QueryUser(string strUserName)
{
    ObservableCollection<myObject> _users = new ObservableCollection<myObject>();

    //do stuff

    return _users;
}

-------------------------------编辑--------------- --------------------------

以下是我的代码如何工作的详细示例

模特: -

EntryAccess.cs //创建了类,因为我无法从另一个项目中实例化第三方dll

    public static ObservableCollection<UserTweet> QueryUserTimeline(string strScreenName)
    {
        ObservableCollection<UserTweet> _userTweets = new ObservableCollection<UserTweet>();
        UserActions userActions = new UserActions();
        _userTweets = userActions.QueryUserTimeline(strScreenName);
        return _userTweets;
    }

UserActions.cs

使用LinqToTwitter;

    public ObservableCollection<UserTweet> QueryUserTimeline(string strScreenName)
    {
        ObservableCollection<UserTweet> _userTweets = new ObservableCollection<UserTweet>();
        var statusTweets =
                        from tweet in twitterCtx.Status
                        where tweet.Type == StatusType.User
                              && tweet.ScreenName == strScreenName  
                        select tweet;

        foreach (var tweet in statusTweets)
        {
            UserTweet userTweet = new UserTweet();

            userTweet.ProfileImage = tweet.User.ProfileImageUrl;
            userTweet.TweetText = tweet.Text;
            userTweet.UserName = tweet.User.ScreenName;
            userTweet.Created = tweet.CreatedAt;

            _userTweets.Add(userTweet);
        }
        return _userTweets;
    }

服务: -

service.cs 使用模型;

    public ObservableCollection<UserTweet> QueryUserTimeline(string strScreenName)
    {
        ObservableCollection<UserTweet> _userTweets = new ObservableCollection<UserTweet>();
        _userTweets = EntryAccess.QueryUserTimeline(strScreenName);
        return _userTweets;
    }

IService.cs 使用模型;

    [OperationContract]
    ObservableCollection<UserTweet> QueryUserTimeline(string strScreenName);

App.Config中: -

  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service name="TwitterWCF.Service1">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration=""
          contract="TwitterWCF.IService1">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8732/Design_Time_Addresses/TwitterWCF/Service1/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <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="True" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

0 个答案:

没有答案