3 Replies - 9517 Views - Last Post: 14 November 2011 - 01:12 PM

#1 thursdayniac  Icon User is offline

  • D.I.C Regular

Reputation: 6
  • View blog
  • Posts: 255
  • Joined: 26-April 09

Update Service Reference (Silverlight)

Posted 14 November 2011 - 12:50 PM

Ok so I have 2 solutions, Ill call them Solution1 and Solution2. Solution1 is a Silverlight app, which makes service calles to code in Solution2. Now, I have a class that is defined in Solution2, but is used in both solutions via service reference.

The class looks somethng like:
public class ClassWithList
{
    private List<SomeClass> classList;

    public List<SomeClass> ClassList
    {
       get
       {
	  if (classList == null)
		classList = new List<SomeClass>();
	  return classList;
       } 
       set
       {
          classList = value;
       }			
    }
}



Now, in Solution 1, when I do "Update Service Reference", it autogenerates a copy of this class(somewhat), although it changes my List to an ObservableList.
Now, as you can see, my ClassWithList has no control over it's list.

I would like to change it to something like:
public class ClassWithList
{
    private List<SomeClass> classList;

    public List<SomeClass> ClassList
    {
        get
        {
             if (classList == null)
		classList = new List<SomeClass>();
	     return classList;
        }
    }

    public AddToList(SomeClass someClass)
    {
        classList.Add(someClass);
    }
}



But... when I change my ClassWithList to the above and do a "Update Service Reference", the AddToList method does no get copied. Doing an Update Service reference only seems to copy over members, not methods. Am I just SOL? Or is there a way to get Update Service Reference to copy everything in the original class?

This post has been edited by thursdayniac: 14 November 2011 - 01:00 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Update Service Reference (Silverlight)

#2 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4531
  • View blog
  • Posts: 7,902
  • Joined: 08-June 10

Re: Update Service Reference (Silverlight)

Posted 14 November 2011 - 01:03 PM

With Silverlight, you're pretty much SOL. If this were, say, WPF and WCF, you could extract your types into a library that both classes could share. Unfortunately, you can't share libraries like that with Silverlight, they must be Silverlight Class Libraries.

What "Update Service References" does is read what the web service exposes over the web (the WSDL). This defines the interface of the "web methods" (or the OperationContracts), as well as the members (DataMembers) of the classes marked as DataContracts.

There's no way it could serialize up implementation of the methods on your DataContract classes. All the client can know is the structure of its data.
Was This Post Helpful? 0
  • +
  • -

#3 thursdayniac  Icon User is offline

  • D.I.C Regular

Reputation: 6
  • View blog
  • Posts: 255
  • Joined: 26-April 09

Re: Update Service Reference (Silverlight)

Posted 14 November 2011 - 01:10 PM

I see. Thanks. The reason I wanted to have ClassWithList to have more control over it's list is because there is a boolean flag on the SomeClass, and I would like to count the number of SomeClass object with this flag set to true as I am adding them to the list. But I guess that will not be possible =(
Was This Post Helpful? 0
  • +
  • -

#4 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4531
  • View blog
  • Posts: 7,902
  • Joined: 08-June 10

Re: Update Service Reference (Silverlight)

Posted 14 November 2011 - 01:12 PM

Well, the classes that are generated in silverlight are marked partial, so if you want to add extra code to them, you can create a new file, and make a class of the same namespace and name, also marked as partial, and they'll be compiled as one class.

So you can add your implementation to them, just not have it automatically update.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1