Invoking WCF Service through Javascript

前端 未结 2 631
醉酒成梦
醉酒成梦 2021-01-07 06:38

How can I access the WCF Service through JavaScript? My problem is, I have to access the operation contracts through the JavaScript (my website is not Ajax enabled).
Pre

相关标签:
2条回答
  • 2021-01-07 06:42

    By using XMLHTTP you ARE using ajax.

    There's a full example here:

    jQuery AJAX calls to a WCF REST Service

    0 讨论(0)
  • 2021-01-07 06:52

    Look at the code on the link that I have sent before. Sure U can implement it yourself but it well be a huge effort duplication.

    First, your WCF service must have:

    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    

    Then, on the javascript side, change the

    "Content-Type", "application/x-www-form-urlencoded"
    

    To

    "Content-Type", "application/json"
    

    Remember that the response will be json formated, so having a parser could be useful.

    Why you don't want to use external libs?

    0 讨论(0)
提交回复
热议问题