【问题标题】:Invalid web service call, missing value for parameter even though the parameter is passed无效的 Web 服务调用,即使传递了参数也缺少参数值
【发布时间】:2016-05-13 05:53:59
【问题描述】:

我正在使用以下参数向 URL http://localhost/WebService.asmx/userworkinsert 发送 POST 请求。

UserId=a2eb8a30-68d3-4bfc-9d53-4e655b816df9&WorkId&TimePeriod_To_Month=Jan&NoticePeriodid=2&IsCurrentlyWorking=1&Employ_Type=1&TimePeriod_To_Year=1950&TimePeriod_From_Year=2011&JobProfile=profile&CompanyName=daacompany&JobTitle=dadesignation&Employ_Status

但它响应服务器错误并且消息如下:

{
    "Message": "Invalid web service call, missing value for parameter: 'UserId'.",
    "StackTrace": "   at System.Web.Script.Services.WebServiceMethodData.CallMethod(Object target, IDictionary`2 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"
}

即使参数UserId 随请求一起传递。我不确定我做错了什么。虽然当我使用 web 服务的自动生成表单发送请求时它可以工作。我使用拦截了POST 请求,这些是发送的参数:

UserId=a2eb8a30-68d3-4bfc-9d53-4e655b816df9&WorkId=&JobTitle=xda+designation&CompanyName=xdacompany&IsCurrentlyWorking=1&NoticePeriodid=2&TimePeriod_From_Year=2011&TimePeriod_From_Month=Jan&TimePeriod_To_Year=1950&TimePeriod_To_Month=Jan&JobProfile=xprofile&Employ_Type=1&Employ_Status=

可能是什么问题?

更新 userworkinsertwebservice 声明。

   [WebMethod]
    public string userworkinsert(string UserId, string WorkId, string JobTitle, string CompanyName, string IsCurrentlyWorking
                              , string NoticePeriodid, string TimePeriod_From_Year, string TimePeriod_From_Month, string TimePeriod_To_Year, string TimePeriod_To_Month
                              , string JobProfile, string Employ_Type, string Employ_Status)
    {
        Jobsekeer obj_jobSeeker = new Jobsekeer();

        SqlParameter[] p = new SqlParameter[18];
        if (WorkId != "")
        {
            p[0] = new SqlParameter("@op", 2);
            p[1] = new SqlParameter("@WorkMaster_Id", WorkId);

        }
        else
        {
            p[0] = new SqlParameter("@op", 1);
            p[1] = new SqlParameter("@WorkMaster_Id", DBNull.Value);
        }

        p[2] = new SqlParameter("@UserID", UserId);
        p[3] = new SqlParameter("@JobTitle", JobTitle);
        p[4] = new SqlParameter("@CompanyName", CompanyName);
        p[5] = new SqlParameter("@CityID", DBNull.Value);
        p[6] = new SqlParameter("@Salary", DBNull.Value);
        p[7] = new SqlParameter("@SalaryTakenType", "Per Year");
        p[8] = new SqlParameter("@IsCurrentlyWorking", IsCurrentlyWorking);
        p[9] = new SqlParameter("@NoticePeriod", NoticePeriodid);


        p[10] = new SqlParameter("@TimePeriod_From_Year", TimePeriod_From_Year);
        p[11] = new SqlParameter("@TimePeriod_From_Month", TimePeriod_From_Month);
        p[12] = new SqlParameter("@TimePeriod_To_Year", TimePeriod_To_Year);
        p[13] = new SqlParameter("@TimePeriod_To_Month", TimePeriod_To_Month);

        p[14] = new SqlParameter("@JobProfile", JobProfile);
        p[15] = new SqlParameter("@Employ_Type", Employ_Type);
        p[16] = new SqlParameter("@Employ_Status", Employ_Status);
        p[17] = new SqlParameter("@CreatedBy", UserId);



        string responseresult = "";
        string ressponsetext = "";
        try
        {
            if (obj_jobSeeker.WorkMaster_Insert_Update(p))
            {
                responseresult = "true";
                ressponsetext = "Sucess";
            }
            else
            {
                responseresult = "false";
                ressponsetext = "unsucessful";
            }
        }
        catch (Exception ex)
        {
            responseresult = "false";
            ressponsetext = "unsucessful";
        }
        user.Getinsertupdateresponse obj = new user.Getinsertupdateresponse();
        obj.Getinsertupdateresponseist = new user.clsinsertupdateresponse();
        obj.Getinsertupdateresponseist.response = responseresult;
        obj.Getinsertupdateresponseist.responsemsg = ressponsetext;

        System.Web.Script.Serialization.JavaScriptSerializer SObj = new System.Web.Script.Serialization.JavaScriptSerializer();
        String JsonStr = SObj.Serialize(obj); Context.Response.ContentType = "application/json";

        Context.Response.Write(JsonStr); Context.Response.End();

        return "";

    }

【问题讨论】:

  • 你能粘贴你调用这个方法的代码吗?
  • 你使用WebAPI还是什么?
  • @Marcin 我正在使用 HTTPRequester firefox 插件来发送请求,如果这是您的要求。
  • 我要求后端,服务端。因为当我读到“我正在发送 POST ..”时,我的第一个想法是您正在使用 WebAPI (REST) 作为 Web 服务,对吗?
  • @Marcin 对不起.. 我没有处理服务器端代码,我只是在使用 API。我怎么知道你在问我?

标签: asp.net .net web-services iis


【解决方案1】:

您确定创建了适当的 POST 正文吗?我总是使用这样的东西:

{
"CardId": 26,
"Login": "15462",
"AccessToken": "79f5828b-1e46-47ed-af1f-5d2c3739742b",
"Password": "8TpB9OZqlNkdBBvVfZITEqiM09c=",
"IsPinPresent": true,
"Puk": "",
"GivenName": "My Name"

}

编辑: 尝试将 userId Guid 放入“”

UserId="a2eb8a30-68d3-4bfc-9d53-4e655b816df9"

【讨论】:

    【解决方案2】:

    看起来像下一个参数,WorkId 没有被分配一个值,这会阻碍请求吗?

    【讨论】:

    • 我不这么认为。不。因为我在 处截获的请求并没有为该参数分配值,所以它工作正常。
    • 控制器长什么样?代码接收是如何处理的?
    • 对不起,我对代码库或技术一无所知。虽然我确实可以访问代码。如果你能告诉我在哪里可以找到那部分,那将是一个很大的帮助?
    • 如果您在 Visual Studio 中,请按 CTRL+SHIFT+F,然后搜索“userworkinsert”,您会很快找到相关部分 :)
    • 好吧,这更好——看起来那里有很多东西可能会出错,因为传入的参数在被直接推送到数据库之前根本没有经过检查或验证。在性能方面,使用数据库作为您的“验证”非常慢。话虽如此,我真的看不出用户ID问题上的错误在哪里。您必须对其进行调试才能准确查看崩溃的位置,可能还需要检查数据库是否有错误。
    猜你喜欢
    • 2011-09-22
    • 1970-01-01
    • 1970-01-01
    • 2019-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多