使用JQuery使用WCF Json服务
在我开始之前:我已经阅读了几乎所有关于使用JQuery使用wcf json服务的帖子——没有结果 我有wcf json服务,工作正常。我可以在我的android应用程序中检索数据,所以我认为WCF的部分没有问题。我的脚本看起来像:使用JQuery使用WCF Json服务,jquery,json,wcf,Jquery,Json,Wcf,在我开始之前:我已经阅读了几乎所有关于使用JQuery使用wcf json服务的帖子——没有结果 我有wcf json服务,工作正常。我可以在我的android应用程序中检索数据,所以我认为WCF的部分没有问题。我的脚本看起来像: function btn() { $.ajax({ url: "http://amder.pl/wcftest.svc/GetPracownicy", type: "GET",
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个多小时搜索解决方案,尝试了几十个脚本。。。现在,我请求你们的帮助,所以请不要给我诸如“使用谷歌…”之类的评论
这是我的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端点。您的配置文件中需要类似于下面的内容
<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>
您正在对WCF服务执行基本的HTTP get吗???您还可以设置一个与WCF并行的WebAPI控制器(WebAPI要简单得多,并且专门用于此目的)。如果需要WCF方面的帮助,您需要显示绑定。@arche89仅供参考:如果您在其他域或网站上运行脚本,出于安全原因,jquery将不会执行跨域ajax调用。我赞成使用WebApi来实现json数据。我想我会让一个dll同时从WebApi和WCF访问