1

I have an web service named AEWService.asmx with the following code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace editor
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class AEWService : System.Web.Services.WebService
    {
        [WebMethod]
        public static Dictionary<string, string> TestFunc(string elementToBeModified, string selectedValue)
        {
            Dictionary<string, string> newValues = new Dictionary<string, string>();
            newValues.Add("k1", "val1");
            newValues.Add("k2", "val2");
            return newValues;
        }
    }
}

When I call the webmethod with ajax, I get a 500 error - Unknown web method TestFunc. The ajax call looks like this:

var dataString = JSON.stringify({ 
    "elementToBeModified": "someElement", 
    "selectedValue": "someValue"
});
$.ajax({
  url: 'AEWService.asmx/TestFunc',
  type: "POST",
  data: dataString,
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  success: function (data) {
     // do somethig...
  }
});

I also added the following lines into web.config under tags (I'm not sure what they mean but I hope they are ok):

 <remove verb="*" path="*.asmx"/>
        <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

The code worked perfect when the webmethod was on a aspx page. What's wrong with the asmx?

Thanks!

1
  • Put a try/catch in the web method and see if any error is being raised... Commented Dec 13, 2011 at 13:13

1 Answer 1

4

You can not return a dictionary object from webservice. See this post. http://forums.asp.net/t/1370858.aspx/1

Also don't mark the webmethod as static. Check here Why are Static Methods not Usable as Web Service Operations in ASMX Web Services?

Sign up to request clarification or add additional context in comments.

2 Comments

I was happy if the function trowed an exception about the returning type. But the problem is that I can not call that function :) Thanks!
Silly me ... I copy/pasted the WebMethod from aspx into the asmx and I forgot about the static :) Thanks a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.