【问题标题】:Calling simple WCF service from jQuery - 500 Internal Server Error从 jQuery 调用简单的 WCF 服务 - 500 内部服务器错误
【发布时间】:2012-10-13 15:51:33
【问题描述】:

在过去的 4 个小时里,我一直在查看我能找到的任何关于这个问题的帖子,所以我现在可能有点盲目 ;-)

我正在尝试使用 jQuery 调用一个简单的 WCF 服务。我已经使用 WebMethods 一段时间了,我正在尝试迁移一些。我正在尝试使用您能想象到的最简单的网络服务进行测试:

[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class ForumOperationService : IForumOperationService
{
    public string Horse(string prefixText, int count)
    {
        return "hestWCF";
    }
}

我的 jQuery 调用:

 $(document).ready(function () {
            var hest;
            $.ajax({
                type: "POST",
                datatype: "application/json",
                url: "Services/ForumOperationService.svc/Horse",
                data: { prefixText: 'a', count: 10 },
                success: function (data) {
                    hest = data;
                }
            });
        });

我的 web.config 是这样的:

 <system.webServer>
    <behaviors>
      <endpointBehaviors>
        <behavior name="ServiceAspNetAjaxBehavior">
          <enableWebScript />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    <services>
      <service name="ForumOperationService">
        <endpoint address="" behaviorConfiguration="ServiceAspNetAjaxBehavior"
            binding="webHttpBinding" contract="IForumOperationService" />
      </service>
    </services>
    .... (more stuff)

在 Firebug 中我收到以下错误:

NetworkError: 500 内部服务器错误 - http://localhost:21599/Client/Services/ForumOperationService.svc/Horse

有什么想法吗?

更新

刚刚运行 WCF 测试客户端,得到了这个错误:

ForumOperationService 类型的服务类都定义了一个 ServiceContract 并从类型继承 ServiceContract 论坛运营服务。契约继承只能在 接口类型。 ÿ如果一个类被标记为 ServiceContractAttribute, 它必须是层次结构中的唯一类型 服务合同属性。 ÿ考虑移动 IForumOperationService 类型上的 ServiceContractAttribute 到一个单独的 IForumOperationService 类型实现的接口。

明天会跟进。

【问题讨论】:

  • 你在 WCFTestClient 中试过了吗?也尝试将方法标记为 [WebInvoke]。尽管您的问题看起来更像是您的服务没有受到影响。
  • 我刚刚尝试过,并且更新了帖子 :-) 感谢您的提示!
  • 欢迎您!如果您的方法参数足够简单,WCFTestClient 是在从应用程序代码开始使用它之前进行测试的快速方法。
  • 是的,这条信息是有道理的。现在我正在处理另一个错误。请使用该客户端作为答案发布,然后我会接受。这绝对是服务器错误,该工具将帮助大多数 plp 找到错误:)
  • 当然,我发布了答案。您遇到的另一个错误是什么?

标签: jquery asp.net ajax json wcf


【解决方案1】:

使用 WCFTestClient(.exe) 测试该方法并确认该方法工作正常,否则您将收到实际错误。

如果您的方法参数足够简单,WCFTestClient 是在从应用程序代码开始使用它之前进行测试的快速方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-23
    • 2013-08-10
    • 1970-01-01
    • 1970-01-01
    • 2019-12-10
    • 2013-12-07
    相关资源
    最近更新 更多