【问题标题】:I have an interface implemented in an existing WCF service that I can't add a reference for我在现有 WCF 服务中实现了一个接口,我无法为其添加引用
【发布时间】:2013-04-19 12:04:19
【问题描述】:

我有ASDService.svc:

 namespace StatusSimulator
 {
      [ServiceContract]
      public class ASDService
      {
           [OperationContract]
           public void DoWork()
      }

      [ServiceContract]
      public interface IScheduleTables
      {
            [OperatonContract]
            string getTable(string l, int r, int c)
            [OperatonContract]
            string getTable(string test)
            [OperatonContract]
            string createTable(List<string> lst, int r, int bal)
      }

      public class ScheduleTables:IScheduleTables
      {
               //Interface Implementation
      }
 }

web.config:

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="NewBehavior0">
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <basicHttpBinding>
        <binding name="NewBinding0" />
      </basicHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="NewBehavior0" name="StatusSimulator.ASDService">
        <endpoint address="http://localhost:2405/ASDService.svc" binding="basicHttpBinding"
          bindingConfiguration="NewBinding0" name="ASDEndpoint" contract="StatusSimulator.ASDService" />
        <endpoint address="http://localhost:2405/ASDService.svc" binding ="basicHttpBinding"
          bindingConfiguration="NewBinding0" name="ScheduleTableEndPoint" contract="StatusSimulator.IScheduleTables" />
      </service>
    </services>
  </system.serviceModel>

我所尝试的绝对不会将接口暴露给服务。我唯一能看到的是ASDService.DoWork。如何在预先存在的服务中实现其他类或接口?

我在配置中尝试了两个服务,多个端点。我尝试将接口嵌套在 ASDService 中。我在这里阅读的教程和帖子比我想说的要多。当它坐下来时,我收到了错误

在服务“ASDService”实施的合同列表中找不到合同名称“StatusSimulator.IScheduleTables”。

我很困惑,没有想法,如果这种情况继续下去,我将需要专业的帮助。

【问题讨论】:

    标签: c# asp.net wcf


    【解决方案1】:

    您不应该将服务合同(在具体类 ADsService 上定义)与另一个服务合同 (IScheduleTables) 的实现混在一起。

    我建议您将两个不同的服务合同作为接口(@98​​7654325@ 和IScheduleTables),然后一个实现这两个接口的具体类 - 一些像这样:

    namespace StatusSimulator
    {
          [ServiceContract]
          public interface IASDService
          {
               [OperationContract]
               public void DoWork()
          }
    
          [ServiceContract]
          public interface IScheduleTables
          {
                [OperatonContract]
                string getTable(string l, int r, int c)
                [OperatonContract]
                string getTable(string test)
                [OperatonContract]
                string createTable(List<string> lst, int r, int bal)
          }
    
          public class ServiceImplementation : IADSService, IScheduleTables
          {
             // implement both interfaces here...
          }
     }
    

    至于资源:我会使用这些作为初学者:

    还有几本好书——最著名的是 Michele Leroux Bustamante 的Learning WCF。她涵盖了所有必要的主题,并且以一种非常容易理解和平易近人的方式。这将教您编写高质量、有用的 WCF 服务所需的一切 - 基础知识、中级主题、安全性、事务控制等等。

    【讨论】:

    • 我明白了,我执行了向导,然后在默认工作后放入我的代码。老实说,我尝试注释掉 ASDService 类,因为它不是必需的,但整个事情停止了工作。
    • @Bmo:好吧,在您的 config 中,您指的是ADSService(通过您的&lt;service&gt;name= 属性)。如果你改变它,你也需要更新配置!服务名称必须完全匹配实现该服务的类的完全限定类名称
    • &lt;service behaviorConfiguration="NewBehavior0" name="StatusSimulator.IScheduleTables"&gt; 给了我The type 'StatusSimulator.ASDService', provided as the Service attribute value in the ServiceHost directive...could not be found. 所以我把它改成了Service="StatusSimulator.IScheduleTables 它说我只能使用类。所以我把它改成了实现,我得到了另一个有意义的错误。你能推荐一个资源来学习吗,显然我到目前为止所做的教程没有理解所需的细节,或者我需要选择一个新的职业。
    • @Bmo:您的 ServiceHost 必须使用服务 implementation 类 - 与您必须在 &lt;service name="...."&gt; 属性中使用的相同 - 完全限定实现类的类名 - 不是任何接口....
    • 珍珠圣母。它正在工作。显然你不能超载更多的问题。它不喜欢 getTable(string, string, int) 和 getTable(string)。更改为 getTable2(string)。我无法将必须在 DataContract 中更改的只读属性设置为只读。现在是时候看看我的,开始是一个实验,但花了两天时间的强烈叹息,是否有效。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-08
    相关资源
    最近更新 更多