1

I have the following function on WebService with 3 optional params:

    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string ObtenirPoble(string CP = "", int Codi = 0, string Nom = "")
    {
        List<clsPoble> llista = _r.getListPobles(CP, Codi, Nom);
        JavaScriptSerializer jss = new JavaScriptSerializer();
        string resultat_Json = jss.Serialize(llista);
        return resultat_Json;
    }

The problem is not to make optional params because i already make it on the WebService.
My problem is when i'm sending an ajax call using json with just 1 param like this because it trigger the error before run WebService code

            //Object to send
            var dataObject = {};
            dataObject[config.busqueda] = $(elemId).val();


            var json = JSON.stringify(dataObject);

            $(elemId).autocomplete({
                source: function (request, response) {
                    $.ajax({
                        url: config.webService,
                        data: json,
                        dataType: "json",
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        success: function (data) {
                            //Code...
                        }                            
                    });
                }
             });

And i get the following error "Invalid call to the Web service. Missing value for the parameter".
I know that i can solve this sending default values of all params but my question is if is possible to send just one param and how i can do this?

AitorFDK
  • 101
  • 6
  • Possible duplicate of [Can I have an optional parameter for an ASP.NET SOAP web service](http://stackoverflow.com/questions/1723052/can-i-have-an-optional-parameter-for-an-asp-net-soap-web-service) – Timothy Groote Sep 07 '16 at 11:13
  • you can basically do `var dataObject = {CP:'', Codi:0, Nom:""};' and remove the `contentType: "application/json; charset=utf-8",` in your ajax properties. – Jeric Cruz Sep 13 '16 at 13:28
  • Thanks for your answer but how i said "I know that i can solve this sending default values of all params" – AitorFDK Sep 13 '16 at 15:52

0 Answers0