zoukankan      html  css  js  c++  java
  • jquery调用wcf案例

    ----------根据其他网友总结

    1.在契约接口上添加:[WebInvoke(RequestFormat=WebMessageFormat.Json,ResponseFormat=WebMessageFormat.Json,BodyStyle=WebMessageBodyStyle.WrappedRequest)]

    2.在实现契约的的服务上添加标记:[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

    3.配置文件:

    <system.serviceModel>

               <services >

                         <service name="WebApplication1.guo" >

                         <endpoint address="" behaviorConfiguration="DiggServiceBehavior"  binding="webHttpBinding" contract="WebApplication1.Iguo" />

                         </service>

               </services>

        <behaviors>

          <serviceBehaviors>

            <behavior name="AllenBehavior">

              <serviceMetadata httpGetEnabled="true" />

              <serviceDebug includeExceptionDetailInFaults="false" />

                       </behavior>

          </serviceBehaviors>

          <endpointBehaviors>

                    <behavior name="DiggServiceBehavior">

                         <enableWebScript/>

                     </behavior>

          </endpointBehaviors>

        </behaviors>

        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

      </system.serviceModel>

    4.调用:

    <script type="text/javascript">

            function guo() {

                $.ajax({

                    url: "guo.svc/Show",

                    type: 'post',

                    contentType: 'text/json',

                    data: '{"str":"guozefeng"}',

                    success: function (data) { alert(data.d); },

                    error: function (data) { alert("error"); }

                  });

            }

        </script>

    -------需要注意的:

    ry调用WCF的要点:

      1. [WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]

      2. [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

      3.  binding="webHttpBinding"

      4. <enableWebScript/>

      5.  contentType: 'text/json'

  • 相关阅读:
    软件工程第三次作业
    软件工程第二次实践
    软件工程第一次作业
    剑指offer-重新排序数组,倒置链表
    剑指offer-倒数第k个节点,镜像二叉树,O(1)时间删除链表节点,
    剑指offer-判断树1中是否有树2,合并有序链表,旋转打印二维数组
    matlab基本语法
    C/C++ 二维数组实参形参的总结
    剑指offer-实现power,打印1到n位最大数
    剑指offer-旋转数组,斐波那契数列,比特1的个数
  • 原文地址:https://www.cnblogs.com/guozefeng/p/3426718.html
Copyright © 2011-2022 走看看