• jQuery调用WCF


    jQuery要调用WCF,首先要创建service.svc服务文件,这里边需要注意:

      [ServiceContract(Namespace = "")]
        [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
        public class WCFservice
        {
            [OperationContract]
            //Post方法,Post方法和Get方法二者只能有一种
            [WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
            //Get方法
            //[WebGet(RequestFormat = WebMessageFormat.Json)]
            public string InsertRow(int id,string title,string content)
            {
                return string.Format("您输入的标题是:{0}
    
    您输入的内容是:{1}
    
    此文章的id是:{2}",title,content,id.ToString());
            }
        }

    接下来要修改配置文件

    <system.serviceModel>
            <behaviors>
                <serviceBehaviors>
                    <behavior name="ServiceAspNetAjaxBehavior">
                        <serviceMetadata httpGetEnabled="true" httpGetUrl="" />
                        <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" />
                    </behavior>
                </serviceBehaviors>
                <endpointBehaviors>
                    <behavior name="ServiceAspNetAjaxBehavior">
                        <enableWebScript />
                    </behavior>
                </endpointBehaviors>
            </behaviors>
            <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
            <services>
                <service name="jqueryWCF.WCFservice">
                    <endpoint address="" behaviorConfiguration="ServiceAspNetAjaxBehavior" binding="webHttpBinding" contract="jqueryWCF.WCFservice" />
                </service>
            </services>
        </system.serviceModel>

    前台调用

    $.ajax({
            type: 'post',
            url: '/WCFservice.svc/InsertRow',
            contentType: 'text/json',
            data: '{"id":'+id+',"title":"'+title+'","content":"'+content+'","search":"true"}',
            success: function(msg) {
            var a = eval('('+msg+')');
            if(String(a.d).length>0){alert(a.d);}
            else{alert("服务器超时");}
            }
        });
        }
  • 相关阅读:
    指定HTML标签属性 |Specifying HTML Attributes| 在视图中生成输出URL |高级路由特性 | 精通ASP-NET-MVC-5-弗瑞曼
    传递额外的值 Passing Extra Values |在视图中生成输出URL | 高级路由特性 | 精通ASP-NET-MVC-5-弗瑞曼
    以其他控制器为目标 在视图中生成输出URL
    数组与指针(数组中所有元素的和)
    OC中的指针
    UIScrollView创建相册
    开发之UI篇
    TabBarController
    适配ipone5
    NSDate 哪些事
  • 原文地址:https://www.cnblogs.com/wolfocme110/p/4431945.html
Copyright © 2020-2023  润新知