Passing parameters to a JSON web service in Objective C

后端 未结 2 670
不知归路
不知归路 2020-12-15 13:48

I\'m trying to call a webservice method and pass a parameter to it.

Here is my webservice methods:

    [WebMethod]
    [ScriptMethod(ResponseFormat =         


        
2条回答
  •  旧时难觅i
    2020-12-15 14:27

    Don't take over control of response stream manually. Just change your webservice method a little as below:

    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string GetHelloWorld()
    {
        return "HelloWorld";
    }
    
    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string GetHelloWorldWithParam(string param)
    {
        return "HelloWorld" + param;
    }
    

    Make sure you add [ScriptMethod(ResponseFormat = ResponseFormat.Json)] if you only want to offer Json in return. But if you dont add this, then your method will be capable of handling both XML and Json request.

    P.S. Make sure your web service class is decorated with [ScriptService]

提交回复
热议问题