无效的Web服务调用,即使传递参数也缺少参数值

时间:2016-05-13 05:53:59

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

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

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与请求一起传递。我不确定我做错了什么。虽然它在我使用webservice自动生成表单发送请求时有效。我使用拦截了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=

可能是什么问题?

更新 userworkinsert网络服务声明。

   [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 "";

    }

2 个答案:

答案 0 :(得分: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"

答案 1 :(得分:0)

看起来下一个参数 WorkId 没有分配值,是否会妨碍请求?