I have create ISAPI service in "ISAPI" folder of hive.
Now I want to access this service using rest api. but I'm getting unauthorized error when try to call it.
IDemoService.cs code (Interface file):
namespace ISAPIDemo.ISAPI { [ServiceContract] public interface IDemoService { [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "DemoServiceCall({SampleValue})")] string DemoServiceCall(string SampleValue); } }
DemoService.svc code:
<%@ ServiceHost Language="C#" Debug="true" Service="ISAPIDemo.DemoService" CodeBehind="DemoService.svc.cs" Factory="Microsoft.SharePoint.Client.Services.MultipleBaseAddressWebServiceHostFactory, Microsoft.SharePoint.Client.ServerRuntime, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
DemoService.svc.cs code:
namespace ISAPIDemo.ISAPI { [BasicHttpBindingServiceMetadataExchangeEndpoint] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] [ServiceBehavior(IncludeExceptionDetailInFaults = true)] public sealed class SampleService : IDemoService { public string DemoServiceCall(string SampleValue) { // Write the string to a file. System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\test.txt"); file.WriteLine("In Demo Service"); file.Close(); return "test"; } } }
js code:
$(document).ready(function () { getISAPIData(); }); function getISAPIData() { var serviceUri = "http://xxxxxxxxx/_vti_bin/DemoService.svc/DemoServiceCall(test)"; $.ajax({ type: "GET", contentType: "application/json", url: serviceUri, dataType: "json", success: function (response) { alert('Success' + response); }, error: function (err) { alert('Error ' + err); } }); }
these much code I have written for service and call it into js. Is it any thing that I had missed?