【问题标题】:basic wcf service returns error Service '' has zero application (non-infrastructure) endpoints基本 wcf 服务返回错误服务“”有零个应用程序(非基础设施)端点
【发布时间】:2011-05-16 11:25:06
【问题描述】:

我创建了一个空白 Web 应用程序并添加了一个启用 ajax 的 wcf 服务。 我没有修改我使用的模板提供的实际 svc.cs 文件

namespace SP.WebWCF {
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class ActivateCardV1 {
    // To use HTTP GET, add [WebGet] attribute. (Default ResponseFormat is WebMessageFormat.Json)
    // To create an operation that returns XML,
    //     add [WebGet(ResponseFormat=WebMessageFormat.Xml)],
    //     and include the following line in the operation body:
    //         WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
    [OperationContract]
    public void DoWork() {
        // Add your operation implementation here
        return;
    }

    // Add more operations here and mark them with [OperationContract]
}

}

我已经稍微更新了配置,看起来像这样

 <service name="SP.WebWCF.ActivateCardV1">
    <endpoint address="https://services.mydomain.com" behaviorConfiguration="SP.WebWCF.ActivateCardV1AspNetAjaxBehavior"
      binding="webHttpBinding" contract="SP.WebWCF.ActivateCardV1" listenUri="/" isSystemEndpoint="true" />
  </service>

但是,当我尝试点击服务时,我得到了一个错误

服务“SP.WebWCF.ActivateCardV1”的应用程序(非基础设施)端点为零。这可能是因为找不到您的应用程序的配置文件,或者因为在配置文件中找不到与服务名称匹配的服务元素,或者因为在服务元素中没有定义端点。

我做错了什么?

【问题讨论】:

    标签: .net wcf exception-handling asp.net-ajax wcf-endpoint


    【解决方案1】:

    首先简化和标准化您的服务配置 xml:

    1. 使用 wsHttpBinding。
    2. 使用 http 而不是 https。
    3. 删除 ListenUri 和 isSystemEndpoint
    4. 删除行为配置属性。
    5. 将合同名称添加到路径中。

    还要从您的类中的 ContractAttribute 中删除 (Namespace = "") - 我不确定这是做什么的,但您在配置 xml 的 contract 属性中指定了命名空间。

    简化配置后,它应该如下所示:

    <service name="SP.WebWCF.ActivateCardV1">
        <endpoint address="http://services.mydomain.com/ActivateCardV1" binding="wsHttpBinding" contract="SP.WebWCF.ActivateCardV1"/>
    </service>
    

    如果它有效,您可以开始增加复杂性以找出破坏它的原因。如果它不起作用,应该更容易排除故障(是否有任何错误写入 IIS 日志?)。

    【讨论】:

    • 谢谢 Greg,我已经更新了你现在建议的所有内容我收到一个错误在“SP.WebWCF.ActivateCardV1”类型的方法“DoWork”上声明的 OperationContractAttribute 无效。 OperationContractAttributes 仅对在具有 ServiceContractAttribute 的类型中声明的方法有效。将 ServiceContractAttribute 添加到类型“SP.WebWCF.ActivateCardV1”或从方法“DoWork”中删除 OperationContractAttribute。这是什么意思??
    • OK 让它工作。使用 http 作为端点地址,并使用 webHttpBinding 作为绑定向服务提供完整的 url。感谢您的帮助
    • 对不起 - 我的帖子中有一个错误告诉你删除 ServiceContract 属性 - 我只是说命名空间部分 - 这是导致最新错误的原因!我已经修好了。很高兴你把它整理出来。
    猜你喜欢
    • 2012-04-06
    • 2011-01-20
    • 2019-03-15
    • 2010-11-25
    • 1970-01-01
    • 1970-01-01
    • 2013-05-12
    • 1970-01-01
    相关资源
    最近更新 更多