【问题标题】:Consume WCF Json Service with JQuery使用 JQuery 使用 WCF Json 服务
【发布时间】:2014-04-06 21:11:33
【问题描述】:

开始之前:我已经阅读了几乎所有关于使用 JQuery 使用 wcf json 服务的帖子 - 没有结果。

我有 wcf json 服务LINK 工作正常。我可以在我的 android 应用程序中检索数据,所以我认为 WCF 的部分不是问题。我的脚本如下所示:

        function btn() {
        $.ajax({
            url: "http://amder.pl/wcftest.svc/GetPracownicy",
            type: "GET",
            processData: true,
            contentType: "application/json",
            timeout: 10000,
            dataType: "json",
            success: function (response) {
                alert(response);
            },      
        });
    };

它不起作用。我花了 2 个多小时搜索解决方案,尝试了几十个脚本......现在,我向你寻求帮助,所以请给我一些类似“使用 google ...”之类的 cmets。

这是我的 Web.config 服务部分:

  <system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>    
<services>
  <service name="amder_01.WCFTest">
    <endpoint contract="amder_01.IWCFTest" kind="webHttpEndpoint" />
  </service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

大部分是基于 StackOverflow 的。

【问题讨论】:

  • 您正在对 WCF 服务进行基本的 HTTP 获取???您不妨设置一个与 WCF 并行的 WebAPI 控制器(Web API 更简单,并且专门用于此目的)。如果您需要 WCF 方面的帮助,则需要显示您的绑定。
  • @arche89 仅供参考:如果您在其他域或网站中运行脚本,出于安全原因,jquery 不会执行跨域 ajax 调用。我赞成使用Web API来实现json数据。
  • 我想我会制作一个从 WebApi 和 WCF 访问的 dll

标签: jquery json wcf


【解决方案1】:

您需要为您的 wcf 服务配置一个基本的 http 端点。您需要在配置文件中包含类似于以下内容的内容

<service name="HelloWorld, IndigoConfig, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null">
  <endpoint 
      address="/HelloWorld2/"
      contract="HelloWorld, IndigoConfig, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"
      binding="basicHttpBinding" />
  </endpoint>
</service>
<bindings>
    <basicHttpBinding 
        receiveTimeout="00:00:01"
    />
</bindings>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多