Adding a New DataMember to existing DataContract results in null value

Locked Adding a New DataMember to existing DataContract results in null value

  • Saturday, April 28, 2012 12:37 PM
     
     

    I have a C# wesbite which I support.  I'm trying to add a new datamember to an existing datacontract.   I added the data member:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ServiceModel;
    using System.Runtime.Serialization;

    namespace SDSServices.DataContracts
    {
        [DataContract]
        public class SccmServer
        {
            [DataMember]
            public string ClientSiteCode { get; set; }
            [DataMember]
            public string ServerName { get; set; }
            [DataMember]
            public string ClientComputerName { get; set; }
            [DataMember]
            public string SDSStatus { get; set; }
            [DataMember]
            public string SDSStatus_Msg { get; set; }
            [DataMember]
            public string OperatingSystem { get; set; }
                                                          
        }
    }

    The Bold is the one I added.  This resides on the server side.   On the client form I refreshed the Service Reference, in which the data contract resides on (SDSServices.cs).   Afterwards was able to see the newly created datamember.   However upon testing the value is returning a null value.  For this testing on the server side I'm only populating this datamember with a simple string called "Testing".   (i.e.  sccm.operatingsystem = "Testing")

    When I check the reference.cs I see upon updating the Service Reference, it built everything exactly compared to the other datamembers.  Everything looks like it should work, but only that member is returning a null value.

    Thoughts?  If someone can please help.  I'm really baffled here.

    Thanks!


    • Edited by EdmoundH Saturday, April 28, 2012 12:39 PM
    •  

All Replies

  • Saturday, April 28, 2012 2:51 PM
     
     
    Did you recompile on the client & server side using rebuild all?  All the object files may not of seen the update.

    jdweng

  • Saturday, April 28, 2012 11:05 PM
     
     

    Hey Joel,

    Tried a complete rebuild.  No success.  Still returning a null value, when in fact it should be returning a static string I hardcoded on the service side.

  • Saturday, April 28, 2012 11:13 PM
     
     
    I think that code is only a container that is used to extract the data.  It doesn't add a new columns to the database (or whatever object that contans the data).  I suspect yo are using some sort of <List> and the list also need to be changed.  The <List> could be a ListView or a GridView object.

    jdweng

  • Saturday, April 28, 2012 11:23 PM
     
     

    Here is how it's used in the GetSCCMInstance..Basically it's accessing the user's computer and getting bits of information from the Config Manager:

    string server = "";
                string siteCode = "";
                string computer = "";
                string errmsg = "";
                string sdsStatus = "";
                GetUserID = UserID;
                GetIpAddress = ipAddress;
                try
                {
                    string domain = ConfigurationManager.AppSettings["Domain"];

                   
                   
                    bool retrievedSiteCode = false;

                    try
                    {
                        ConnectionOptions options = new ConnectionOptions();
                        options.Authority = "ntdlmdomain:" + domain;
                        options.Impersonation = ImpersonationLevel.Impersonate;
                        ManagementScope scope = new ManagementScope(@"\\" + ipAddress + @"\root\ccm", options);
                        ManagementClass cls = new ManagementClass(scope.Path.Path, "sms_client", null);
                        ManagementBaseObject outSiteParams = cls.InvokeMethod("GetAssignedSite", null, null);
                        siteCode = outSiteParams["sSiteCode"].ToString();
                        computer = GetComputerName(ipAddress);
                        retrievedSiteCode = true;
                    }
                    catch (Exception ex)
                    {
                        string UserInfo = GetUserInfo(GetIpAddress, GetUserID);
                        string status = String.Format("There was a problem getting the SCCM site code for IP address: {0}.", ipAddress);
                        LogHelper.LogApplicationError(logSource, ex, status, UserInfo);
                        errmsg = ex.Message;
                        sdsStatus = "NoSiteCode";
                                                              
                    }
                    if (retrievedSiteCode)
                    {
                        string key = String.Format("SiteCode:{0}", siteCode);
                        if (ConfigurationManager.AppSettings.AllKeys.Contains(key))
                        {
                            server = ConfigurationManager.AppSettings[key];
                                                }
                        else
                        {
                            string UserInfo = GetUserInfo(GetIpAddress, GetUserID);
                            string status = String.Format("Get SCCM instance for IP address '{0}' is missing site code key: {1}.", ipAddress, key);                       
                            LogHelper.LogApplicationError(logSource, new Exception(), status,UserInfo);
                            errmsg = "Get SCCM instance";
                            sdsStatus = "ErrOnGettingServer";
                           
                        }
                    }
                    //SccmServer sccm = new SccmServer();
                    //sccm.ClientSiteCode = siteCode;
                    //sccm.ServerName = server;
                    //sccm.ClientComputerName = computer;
                    //return sccm;
                   
                                                      
                }
                catch (Exception ex)
                {
                    string status = String.Format("There was a problem getting the SCCM instance by IP address: {0}.", ipAddress);
                    string UserInfo = GetUserInfo(GetIpAddress, GetUserID);
                    LogHelper.LogApplicationError(logSource, ex, status,UserInfo);
                    errmsg = ex.Message;
                    sdsStatus = "NoSCCMClient";
                    throw ex;
                }

                SccmServer sccm = new SccmServer();
                if (sdsStatus == "")
                {
                    if (server != "")
                    {
                        sccm.SDSStatus = "AccessGranted";
                        sccm.SDSStatus_Msg = "";
                    }
                    else
                    {
                        sccm.SDSStatus = "AccessDenied";
                        sccm.SDSStatus_Msg = "UserID: " + UserInfo + " from Site: " + siteCode + ". Site Opted Out to use SDS Application, however user tried to access SDS.";
                        }
                }
                else
                {
                    sccm.SDSStatus = sdsStatus;
                    sccm.SDSStatus_Msg = errmsg;
                }           
                sccm.ClientSiteCode = siteCode;
                sccm.ServerName = server;
                sccm.ClientComputerName = computer;
                sccm.OperatingSystem = "Testing";
               
                return sccm;

    That's in the SDSServices Project in my SDS Solution.  In the WebFrontEnd project under the same solution, it uses the using SDS.SDSServices;

    During the Page.Load that's when it triggers:

    using (SDSServicesClient client = new SDSServicesClient())
                        {                       
                            string userLoginName = Page.User.Identity.Name;                              
                            SccmServer server = client.GetSCCMInstance(Request.UserHostAddress, userLoginName);
                            client.Close();
                            sdsstatus = server.SDSStatus;
                            errmsg = server.SDSStatus_Msg;

    ...

    Thoughts?

  • Saturday, April 28, 2012 11:42 PM
     
     

    There are a bunch of if else conditions so add this line to prove your change is working.  After you prove it remove the line otherwise, you will never get real databack

                SccmServer sccm = new SccmServer();     ***Note this is the line that get the data

     ADD --> sccm.OperatingSystem = "Initialized";

                if (sdsStatus == "")

    The code is being set in the constructor for the Class SccmServer.  You need ot look at that class. 


    jdweng

  • Sunday, April 29, 2012 1:02 AM
     
     

    So I added on a client page in the Page load:

    SccmServer sccm = new SccmServer();
                sccm.OperatingSystem = "Testing";
                lblTest.Text = sccm.OperatingSystem;

    And it displayed correctly.   So it's something on the server end?  The SccmServer class is the DataContract (see original post).   All the other values in the datacontract populate.

  • Sunday, April 29, 2012 7:43 AM
     
      Has Code

    If you look where siteCode variable is being loaded it is in the code below.  The code logon to the server and returs the array outsiteParams.  The code you changed only creates a structure to store that results of the array.  So you need three additional changes

    1) Add a new variable at the beginning of the function where siteCode gets declared. 

    string  OperatingSystem = "";   <-- add at beginning of function with other declarations

    2) Something like the code below.  [OperatingSystem] must be spelled exactly like the field in the server database

    OperatingSystem = outSiteParams["OperatingSystem"].ToString();   <-- Add to code below

    3) Add the line here

    sccm.ClientSiteCode = siteCode;                     <-- this line already exists

    sccm.OperatingSystem = OperatingSystem;    <-- add new

    This queries the databasse and returns siteCode                   

                       ConnectionOptions options = new ConnectionOptions();
                        options.Authority = "ntdlmdomain:" + domain;
                        options.Impersonation = ImpersonationLevel.Impersonate;
                        ManagementScope scope = new ManagementScope(@"\\" + ipAddress + @"\root\ccm", options);
                        ManagementClass cls = new ManagementClass(scope.Path.Path, "sms_client", null);
                        ManagementBaseObject outSiteParams = cls.InvokeMethod("GetAssignedSite", null, null);
                        siteCode = outSiteParams["sSiteCode"].ToString();


    jdweng

  • Sunday, April 29, 2012 11:59 PM
     
     Answered

    UPDATE

    So I was testing on my live environment server using a separate website so to not interfere with the one used by my clients.  I decieded to delete my "tester" site and update the main sites content.  Volla! The field is now populating!

    Very odd why it wasn't working.  Even though I was on another site it must have been using the current SDSServices.dll file. 

    Joel, I wanted to thank you for your help.  I really appreciate it.  Now that I know where the issue lies, I can work on that.

    • Marked As Answer by EdmoundH Sunday, April 29, 2012 11:59 PM
    •