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

좋은 웹페이지 즐겨찾기