jQuery 调用 WCF中的方法

来源:互联网 发布:在淘宝网上怎么开店 编辑:程序博客网 时间:2024/06/08 07:55

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);                    }                }                );




原创粉丝点击