代码之家  ›  专栏  ›  技术社区  ›  David.Chu.ca

WCF REST web服务:找不到约定名称

  •  1
  • David.Chu.ca  · 技术社区  · 16 年前

    我正在使用WCF REST Start kit构建一个RESTFul服务。我定义了这样一个服务:

    namespace MyNS {
      [ServiceBehavior(IncludeExceptionDetailInFaults = true, 
       InstanceContextMode = InstanceContextMode.Single,
       ConcurrencyMode = ConcurrencyMode.Single)]
      [AspNetCompatibilityRequirements(
       RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
      public class MyService : MyCollectionServiceBase, IMyCollectionServiceBase 
      {...}
    }
    

    MyCollectionServiceBase和IMyCollectionSeviceBase的定义如下:

    namespace MyNS.Contract {
      [ServiceContract]
      public interface IMyCollectionServiceBase<TItem> where TItem : class 
      {...}
    
      // COllectionServiceBase is an abstract class in 
      // Microsoft.ServiceModel.Web.SpecializedServices
      public abstract class MyCollectionServiceBase<TItem> :
        CollectionServiceBase<TItem>
        where TItem : class
      {...}
    }
    

    <serviceBehaviors>
      ...
      <behavior name="MyNS.MyService1Behavior">
        <serviceMetadata httpGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="false" />
      </behavior>
    </serviceBehaviors>
    ...
    <service behaviorConfiguration="MyNS.MyService1Behavior"
      name="MyNS.MyService1">
      <endpoint address="" binding="wsHttpBinding" 
        contract="MyNS.IMyService1">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    </service>
    

    当我测试我的服务时使用“ http://localhost:1290/MyService.svc/ “,我收到错误消息说:

    The contract name 'MyNS.Contract.IMyCollectionServiceBase' could not be found 
    in the list of contracts implemented by the service 'MyService'.
    

    我不确定端点是否不匹配或缺少什么?

    2 回复  |  直到 16 年前
        1
  •  2
  •   marc_s MisterSmith    16 年前

    你应该读一下 An Introduction To RESTful Services With WCF

    您当前的服务配置正在使用 wsHttpBinding 哪个是 休息(但肥皂代替)-你不需要使用 webHttpBinding 相反。

    [WebGet] 或者 [WebInvoke] 属性,并可选地提供参数来定义应该如何准确地调用和响应httpuri。

        2
  •  1
  •   David Hoerster    16 年前

    [OperationContract()]
    [WebGet(...)]
    [ServiceKnownType(typeof(IMYCollectionServiceBase))]
    IWhatever MyServiceOperation(...);
    

    如果不是这样,请使用web.config设置更新您的帖子。