简体   繁体   English

使用WCF服务进行的Ajax jQuery调用

[英]Ajax Jquery call made with WCF service

I have found tons of articles and posts about making jquery ajax calls to WCF services. 我发现了大量关于WCF服务的jquery ajax调用的文章和帖子。 I cannot seem to find one good tutorial for doing this in .net 4.5. 我似乎找不到在.net 4.5中执行此操作的好教程。 I have found an msdn blog post that claims to allow you to do it, but it does not work. 我发现一个msdn博客文章声称允许您执行此操作,但是它不起作用。 Below is what it claims is all you need to change in your web.config and everything else can be left as the basic template code it comes with. 下面声称它是您需要在web.config中进行更改的所有内容,其他所有内容都可以作为其附带的基本模板代码保留。

    <services>
  <service name="WcfServiceAjax.Service">

    <endpoint address="ajaxEndpoint" behaviorConfiguration="AjaxBehavior"
     binding="webHttpBinding" bindingConfiguration="AjaxBinding" 
     contract="WcfServiceAjax.IService"></endpoint>

    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:62069"/>
      </baseAddresses>
    </host>

  </service>

When I try to invoke the service either directly using this 当我尝试使用此方法直接调用服务时

 http://localhost:62069/Service.svc/GetData

I just get a 404 error when I try invoking it with 当我尝试使用404错误时,我只会收到404错误

  <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
 <script>

  $.ajax({
    type: "POST",
    url: "Service.svc/GetData",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (msg) {
        alert(msg.d);
    },
    error: function () {
        alert('eh, fack!');
    }
});
</script>

I get "Failed to load resource". 我收到“无法加载资源”。 I really am just looking for a single easy to follow tutorial on how to call a WCF service with jQuery ajax in .net 4.5. 我真的只是在寻找一个简单易学的教程,该教程如何在.net 4.5中使用jQuery ajax调用WCF服务。 I understand there are a lot of posts like this one, but I have yet to find one targeting 4.5 directly. 我知道有很多这样的帖子,但是我还没有找到直接针对4.5的帖子。

Thank you 谢谢

我认为404错误是因为您的Ajax调用调用Service.svc/GetData而您的服务在以下端点地址可用: <endpoint address="ajaxEndpoint"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM