2

我创建了一个空白 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”的应用程序(非基础设施)端点为零。这可能是因为没有为您的应用程序找到配置文件,或者因为在配置文件中找不到与服务名称匹配的服务元素,或者因为在服务元素中没有定义端点。

我究竟做错了什么?

4

1 回答 1

1

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

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

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

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

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

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

于 2010-11-27T06:09:23.883 回答