0

I am trying to create a method with class as a parameter. But it's throwing error. After some search I found the implementation of QueryStringConverter. I am trying to do it but I didn't have much knowledge in it.

In my service class, the method is :

[WebInvoke(UriTemplate="LogInForMobileWithDeviceNo", Method="POST", RequestFormat=WebMessageFormat.Json, ResponseFormat=WebMessageFormat.Json, BodyStyle=WebMessageBodyStyle.Wrapped)]
string LogInForMobileWithDeviceNo(clsUserDeviceInfo userDeviceInfo);

In the clsUserDeviceInfo class, i declared the properties as:

    [DataContract]
    public class clsUserDeviceInfo
    {
        [DataMember]
        public string UserID{get;set;}
        [DataMember]
        public string DeviceName{get;set;}
        [DataMember]
        public string CordovaVersion{get;set;}
        [DataMember]
        public string DevicePlatformJs{get;set;}
        [DataMember]
        public string DeviceUID{get;set;}
        [DataMember]
        public string DeviceModel { get; set; }
        [DataMember]
        public string DeviceVersion { get; set; }
    }

but it's not working.

using Jquery i did Ajax posting:

 var DeviceName = "samsung";
        var CordovaVersion = "2.1.1.1";
        var DevicePlatformJs = "windows 8";
        var DeviceUID = "23dswd-234dff-23-2334nhj";
        var DeviceModel = "grand duos";
        var DeviceVersion = "3.2";
         var DataArr = {DeviceName:DeviceName,CordovaVersion:CordovaVersion, DevicePlatformJs:DevicePlatformJs,DeviceUID:DeviceUID,DeviceModel:DeviceModel,DeviceVersion:DeviceVersion};
         $.ajax({
            type: "GET",               
            url: serverurl,
        data: JSON.stringify(DataArr),
            success: function (result) {
                alert(result);
            },
            accept: 'application/json'
        });

Am I doing anything wrong?

RajeshKannan
  • 894
  • 2
  • 16
  • 32

1 Answers1

0

Do you have a OperationContract, this should work!

     [OperationContract]
      [WebGet(BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/LogInForMobileWithDeviceNo?userDeviceInfo={userDeviceInfo}")]
string LogInForMobileWithDeviceNo(clsUserDeviceInfo userDeviceInfo);
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • i tried it. Querystringconverter error is not throwing,but it's not working. I am passing the data from AJAX Post and it was not working. I don't know where the problem is? I will Edit my post with the AJAX Post. Pls see it. – RajeshKannan Sep 25 '13 at 09:31
  • check now, you have not mentioned it as a get method – Sajeetharan Sep 25 '13 at 16:21
  • I did the changes as suggested by you, but it's not working. When I run it it is throwing the error as ==> Variables for UriTemplate query values must have types that can be converted by 'QueryStringConverter'. – RajeshKannan Sep 26 '13 at 06:05
  • Problem with your jquery, if its a simple project upload somewhere will fix it – Sajeetharan Sep 26 '13 at 06:06
  • I didn't post from jquery, I did the changes in WCF project and on pressing F5 it's throwing the error as I mentioned in the above comment . If it is WebInvoke it is not throwing error, but if it is WebGet it is throwing the error. – RajeshKannan Sep 26 '13 at 06:24