jQuery 调用 WCF中的方法

TestWebService.svc


 [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class TestWebService
    {
        // 要使用 HTTP GET,请添加 [WebGet] 特性。(默认 ResponseFormat 为 WebMessageFormat.Json)
        // 要创建返回 XML 的操作,
        //     请添加 [WebGet(ResponseFormat=WebMessageFormat.Xml)],
        //     并在操作正文中包括以下行:
        //         WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
        [OperationContract]
        public void DoWork()
        {
            // 在此处添加操作实现
            return;
        }

        [OperationContract]
        [WebGet()]
        public string GetString()
        {
            return "Helle An !";
        }

        [OperationContract]
        public string GetTimeFormat(string format)
        {
            return DateTime.Now.ToString(format);
        }

        [OperationContract]
        [WebGet()]
        public string HelloWorld()
        {
            return "Hello World";
        }

        // 在此处添加更多操作并使用 [OperationContract] 标记它们
    }



Test.html



$.ajax(
                {
                    url: "TestWebService.svc/HelloWorld",
                    type: "get",
                    success: function (data)
                    {
                        alert(data.d);
                    }
                }
                );




你可能感兴趣的:(jquery,function,String,Class,WCF)