0

我正在尝试创建一个以类为参数的方法。但它抛出错误。经过一番搜索,我找到了implementation of QueryStringConverter. 我正在尝试这样做,但我对此没有太多了解。

在我的服务类中,方法是:

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

clsUserDeviceInfo类中,我将属性声明为:

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

但它不起作用。

使用 Jquery 我做了 Ajax 发布:

 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'
        });

我做错什么了吗?

4

1 回答 1

0

你有一个 OperationContract,这应该可以!

     [OperationContract]
      [WebGet(BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/LogInForMobileWithDeviceNo?userDeviceInfo={userDeviceInfo}")]
string LogInForMobileWithDeviceNo(clsUserDeviceInfo userDeviceInfo);
于 2013-09-25T06:22:51.073 回答