Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have always used jQuery.ajax to retrieve data from listdata.svc or lists.asmx in SharePoint and from some custom web services. Now I will try Microsoft Ajax Library and especially ServiceReference in ASP.NET which can be added to ScriptManager. Then javascript proxy should be created automatically.

Here is my ServiceReference in the masterpage:

<asp:ScriptManager id="ScriptManager" runat="server" 
  EnablePageMethods="false" 
    EnablePartialRendering="true" 
  EnableScriptGlobalization="false" 
    EnableScriptLocalization="true">
    <Services>
        <asp:ServiceReference Path="/_vti_bin/lists.asmx" />
    </Services>
</asp:ScriptManager>

When I try this I get the 401 error:

GET http://dev/_vti_bin/lists.asmx/jsdebug 401 (Unauthorized)

enter image description here

Has anyone tried ServiceReference in SharePoint?

EDIT (2012-02-20): I want to call a custom wcf like Wictor Wilén. It works very well with jquery ajax. My custom.svc file is:

<%@ ServiceHost 
    Debug="true" 
    Language="C#" 
    Service="Takana.WCFService,Takana, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0c0327f8b01d9792" 
    Factory="Microsoft.SharePoint.Client.ServerRuntime, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

I tried to replace with a simple .NET example, with no success:

<%@ ServiceHost 
    Debug="true" 
    Language="C#" 
    Service="Takana.WCFService" 
    Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory" %>
share|improve this question
add comment

2 Answers 2

up vote 3 down vote accepted
+50

The service needs to be AJAX enabled to generate a javascript proxy for you. Lists.asmx is not AJAX enabled.

[WebServiceBinding(ConformsTo=WsiProfiles.BasicProfile1_1), WebService(Namespace="http://schemas.microsoft.com/sharepoint/soap/")]
public class Lists : GenericService, ISoapServiceLists, ISoapServiceListData, ISoapServiceListSchema, IListSoapServiceContentTypes
{
}

For more information see Understanding ASP.NET AJAX Web Services

share|improve this answer
    
You are right, but when I add my custom wcf service as reference, it doesn't generate any javascript proxy. –  Anatoly Mironov Feb 15 '12 at 12:33
    
You have to make sure you properly configure your custom WCF to auto generate a javascript proxy as well. See msdn.microsoft.com/en-us/library/bb628467.aspx and msdn.microsoft.com/en-us/library/bb628607.aspx for more information. –  Rob Windsor Feb 15 '12 at 14:37
    
Have you used it with SharePoint, Rob? I just doesn't work here. I added namespace to my contract, added the stuff to web.config. I just wonder if this problem is just sharepoint-related. –  Anatoly Mironov Feb 23 '12 at 9:37
    
Yes. This blog post series - ybbest.wordpress.com/2011/07/17/… - has more information. Perhaps it will help. The only thing you might need to change is the security on the service binding. If your SharePoint development machine is running Windows 7 then you'll probably need to use Windows authentication rather than Ntlm. –  Rob Windsor Feb 24 '12 at 16:18
add comment

Dare i ask why you wouldn't just use SPServices (created by @sympmarc), an open source jQuery plugin that wraps methods in the OOTB SharePoint Web / WCF Services, making the use of these services in JavaScript as simple as the following example:

$(document).ready(function() {
  $().SPServices({
    operation: "GetListItems",
    async: false,
    listName: "Announcements",
    CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>",
    completefunc: function (xData, Status) {
      $(xData.responseXML).SPFilterNode("z:row").each(function() {
        var liHtml = "<li>" + $(this).attr("ows_Title") + "</li>";
        $("#tasksUL").append(liHtml);
      });
    }
  });
});
share|improve this answer
    
Or a straight SharePoint object model call with JavaScript, if you don't want to include jQuery/SPServices in your overhead. –  webdes03 Feb 17 '12 at 23:00
    
Thank you @Colin, I like SPServices and your solution. But I am discovering ASP.NET and SharePoint's built-in possibilities in order to (maybe) improve or (at least) evaluate it. I have used listdata.svc and Client Object Model. I think I'll use more SPServices. But the question remains. What have I to do to enable a native asp.net javascript proxy for my web services. –  Anatoly Mironov Feb 20 '12 at 9:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.