locked
Error Json WCF Service RRS feed

  • Question

  • User-1953432065 posted

    i have error with json wcf service

    Operation 'check_Login' of contract 'IService' specifies multiple request body parameters to be serialized without any wrapper elements. At most one body parameter can be serialized without wrapper elements. Either remove the extra body parameters or set the BodyStyle property on the WebGetAttribute/WebInvokeAttribute to Wrapped.

    and this is my code in Iservice.cs

     [ServiceContract]
        public interface IService
        {
            [OperationContract]
            bool check_Login(string mssv, string pwd);
    
            [OperationContract]
            [WebGet(RequestFormat = WebMessageFormat.Json,
                ResponseFormat = WebMessageFormat.Json,
                BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "Diem"
                )]
            Diem[] GetAllDiem();
        }
    
        // Use a data contract as illustrated in the sample below to add composite types to service operations.
        [DataContract]
        public class Diem
        {
            [DataMember]
            public string mssv { get; set; }
            [DataMember]
            public string mamon { get; set; }
            [DataMember]
            public string tenmon { get; set; }
            [DataMember]
            public float diem30 { get; set; }
            [DataMember]
            public float diem70 { get; set; }
            [DataMember]
            public float diemtong { get; set; }
        }
        [DataContract]
        public class User
        {
            [DataMember]
            public string mssv { get; set; }
            [DataMember]
            public string pwd { get; set; }
        }

    thanks!


    Wednesday, July 24, 2013 12:34 PM

Answers

  • User-742633084 posted

    Hi ntaakasb,

    The error message you provide indicates that there is something wrong with the parameter wrapping of the "check_login" service operation. So we need to do some modification on the declaration of "check_Login" operation. I think you can consider the following approach:

    You can try defining the operation parameters as querystring parameter of the REST operation URL. e.g.

     

      [WebGet(UriTemplate="/check_Login?mssv={mssv}&pwd={pwd}")]             
    bool check_Login(string mssv, string pwd);

     

    Thus, when client invoke the service operation, it can supply the parameters in url querystring.

    Or you can also consider using "WebInvoke" (HTTP POST method) for the operation so that the parameters will be sent via HTTP request body:

     

    [WebInvoke(UriTemplate="/check_Login")]             
    bool check_Login(string mssv, string pwd);
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 25, 2013 6:05 AM

All replies

  • User-742633084 posted

    Hi ntaakasb,

    The error message you provide indicates that there is something wrong with the parameter wrapping of the "check_login" service operation. So we need to do some modification on the declaration of "check_Login" operation. I think you can consider the following approach:

    You can try defining the operation parameters as querystring parameter of the REST operation URL. e.g.

     

      [WebGet(UriTemplate="/check_Login?mssv={mssv}&pwd={pwd}")]             
    bool check_Login(string mssv, string pwd);

     

    Thus, when client invoke the service operation, it can supply the parameters in url querystring.

    Or you can also consider using "WebInvoke" (HTTP POST method) for the operation so that the parameters will be sent via HTTP request body:

     

    [WebInvoke(UriTemplate="/check_Login")]             
    bool check_Login(string mssv, string pwd);
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 25, 2013 6:05 AM
  • User503812343 posted

    you haven't set the WebGet attribute details for the Operation check_login. You need to mark the WebGet details with this Operation and sepcify Request/Reply format details.

    For more info on WCF JSON and its operation formating click here

    Thursday, July 25, 2013 10:50 AM