Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7065555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:58:14+00:00 2026-05-28T04:58:14+00:00

I have a web method that can accept a XElement argument and I want

  • 0

I have a web method that can accept a XElement argument and I want to call it using jQuery Ajax. I can call simple methods using jQuery Ajax with simple argumnets(such as int,string,…), but I don’t know how pass to a complex type using jQuery Ajax.


Edit 1)

I have a simple web service :

[WebMethod]
public bool MyGetPassXML(System.Xml.XmlDocument nima)
{
    try
    {
        if (nima == null )
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    catch (Exception ex)
    {
        return false;
    }
} 

For the call I’ve written this code:

var xmlFragment = ‘AB’;

$("#Button2").click(function() {
    $("#Loader").show();
    $.ajax({
        type: "POST",
        url: "WebService.asmx/MyGetPassXML",
        data: "{'nima':'" + xmlFragment + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(result) {
            $("#Loader").hide();
            alert('OK');
        }
    });
});

I’ve test it with Firefox and see request an response with FireBug but I get this error:

{“Message”:”Cannot convert object of type \u0027System.String\u0027 to type \u0027System.Xml.XmlDocument\u0027″,”StackTrace”:” at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)\r\n at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)\r\n at System.Web.Script.Services.WebServiceMethodData.StrongTypeParameters(IDictionary2 rawParams)\r\n at System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary2 parameters)\r\n at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)”,”ExceptionType”:”System.InvalidOperationException”}

I change System.Xml.XmlDocument to XElement but again I get this error. How can I solve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:58:15+00:00Added an answer on May 28, 2026 at 4:58 am

    Instead of XmlDocument as the web method argument type, I would change it to a string. You can create an XmlDocument from a string by calling .LoadXml(nima).

    Edit to answer the request for an example:

    Let’s say you had a simple class like the following (forgive my c#):

    public TestClass {
    
      public string Var1 { get; set; }
      public string Var2 { get; set; }
    
      public string void TestClass() 
      {
    
      }
    
    }
    

    And a web method like the following:

    [WebMethod]
    public bool MyGetPassJSON(TestClass nima)
    {
      // do something
    } 
    

    And your javascript / jquery could look like the following:

       $.ajax({
            type: "POST",
            url: "WebService.asmx/MyGetPassJSON",
            data: "{nima: {Var1:'something',Var2:'something else'}}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(result) {
                $("#Loader").hide();
                alert('OK');
            }
        });
    

    In your case, you could have:

    "cities": ["A", "B","C","D"]
    

    This is a very simple example, but much more complex parameters are possible. You can also build up your json as a proper javascript object and use JSON.stringify to send it to your web method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have web service written that generates some data...can I call the web service
I have a Web Service with Just one Web Method that returns a boolean
I have a web service (ASMX) and in it, a web method that does
I have a problem with a oneway web method that open a moss site
Some existing web services I consume have methods that look something like this: List<Employee>
I have a web application that will need to access code behind methods as
I am using jquery ajax method on my aspx page,which will invoke the webmethod
I have a C# web method that I need to translate to VB.NET. The
I have to call a Web service that is extremely demanding (unstandard) regarding the
I have a web service that I can only hit if I'm logged into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.