2

I had create .asmx webservice in asp.net projects. my doubts that is this able to use this webservice in sharepoint project?

suppose this is my code

source: function (request, response) {
                $.ajax({
                    url: "http://localhost:54946/VishalSir/UserName.asmx/FetchEmailList?callback=",
                    data: "{ 'mail': '" + request.term + "' }",
                    dataType: "json",
                    type: "POST",
                    crossDomain: true,
                    contentType: "application/json; charset=utf-8",
                    dataFilter: function (data) { return data; },
                    success: function (data) {
                        response($.map(data.d, function (item) {
                            return {
                                value: item.Email
                            }
                        }))
                    },

its works in .net project but i have taken Add Service references in sharepoint projects use this script but its not work.. pl give me direction?

  • Just for clarity, this is jQuery running on the client, right? – SPDoctor Nov 26 '11 at 9:12
  • yep..i had fetch data using ajax with json type..its work in normal localhost but not work in sharepoint webapplication. – Jignesh Rajput Nov 26 '11 at 9:19
  • Sorry, I can't see why this code would behave differently in the context of a SharePoint application, since it is client-side code calling your web service. If you tell us what you mean by "does not work" someone may recognize the problem, otherwise I'm not sure we can help you with the information given. – SPDoctor Nov 26 '11 at 10:01
3

Yes, you can use web services from within SharePoint. Since you are in this case using jQuery and will likely go from one domain (URL) to another (that is cross domain), you cannot use JSON as it is, but instead have to rely on JSONP.

I've written an example of usage in a post, where the SharePoint site is hosted in Office 365/SharePoint Online and the service is hosted in Azure. Check out: http://www.wictorwilen.se/Post/SharePoint-Online-and-External-Data-using-JSONP.aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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