WCF不返回数据

时间:2015-03-02 06:58:42

标签: c# wcf windows-services wcf-data-services

我有wcf服务作为一个单独的项目,我已经添加了对Windows服务项目的引用。我面临的问题是,当我调用wcf的方法时,它只是在字段中返回null,但它从服务返回ok。下面是我的代码片段。

WCF服务

    // composite types for service operations.
[DataContract]
public class pushNotification
{
    [DataMember]
    public string Message { get; set; }

    [DataMember]
    public bool toiOS { get; set; }

    [DataMember]
    public bool toAndroid { get; set; }
}

 [OperationContract]
 [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "getDeviceIds")]
 string[] GetDeviceIds();

 [OperationContract]
 [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "getPendingNotification")]
 pushNotification GetPendingNotification();

    public string[] GetDeviceIds()
    {
        try
        {

            wmas_subsDataContext dc = new wmas_subsDataContext();

            var tbdeviceids = dc.tbDeviceIds.ToList();
            string[] Ids = new string[tbdeviceids.Count-1];
            int i = 0;

            foreach (var item in tbdeviceids)
            {
                Ids[i] = item.DeviceId;
                i++;
            }

            return Ids;
        }

        catch (Exception ex)
        {
            LogFile.WriteException(ex);
            throw ex;
        }
    }

    public pushNotification GetPendingNotification()
    {
        try
        {

            wmas_subsDataContext dc = new wmas_subsDataContext();
            pushNotification push_notification = new pushNotification();

            var ObjNotification = dc.tbPushNotifications.ToList();

            if (ObjNotification.ToList().Count > 0)
            {                    
                push_notification.Message = ObjNotification.First().Message;
                push_notification.toAndroid = Convert.ToBoolean(ObjNotification.First().toAndroid);
                push_notification.toiOS = Convert.ToBoolean(ObjNotification.First().toAndroid);                    
            }

            return push_notification;
        }

        catch (Exception ex)
        {
            LogFile.WriteException(ex);
            throw ex;
        }
    }

Windows服务

   pushNotification push_notification = new pushNotification();
   ServiceReference1.ClientServiceClient proxy = new ServiceReference1.ClientServiceClient();

            using (var scope = new OperationContextScope(proxy.InnerChannel))
            {
                // Add a HTTP Header to an outgoing request

                HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
                requestMessage.Headers["Authorization"] = "Push Notification";
                OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;
                push_notification = proxy.GetPendingNotification();

            }

我在“push_notification”中没有得到任何值,所有字段都为空。

0 个答案:

没有答案