XML Web Services question
-
After playing with XML Web Services a little bit, it looks like all the data members of any custom object that need to be serialized across should be marked as public. This seems so non O-Oish or is this a limitation of the WSDL that gets generated automatically that it only supports public data members. For e.g.
[Serializable] public class SomeData { public string _id; // if this is marked private, WSDL ignores it public string Id { get { return _id; } } }
Is there a way around this? Chen Venkataraman -
After playing with XML Web Services a little bit, it looks like all the data members of any custom object that need to be serialized across should be marked as public. This seems so non O-Oish or is this a limitation of the WSDL that gets generated automatically that it only supports public data members. For e.g.
[Serializable] public class SomeData { public string _id; // if this is marked private, WSDL ignores it public string Id { get { return _id; } } }
Is there a way around this? Chen VenkataramanIt's due to the way xml serialization works. It doesn't actually remote the object like you would think. What happens is that wsdl.exe creates a class on the client that is serialziation comatible with your class, with none of the methods. It will just be a simple struct with data fields only.
-
After playing with XML Web Services a little bit, it looks like all the data members of any custom object that need to be serialized across should be marked as public. This seems so non O-Oish or is this a limitation of the WSDL that gets generated automatically that it only supports public data members. For e.g.
[Serializable] public class SomeData { public string _id; // if this is marked private, WSDL ignores it public string Id { get { return _id; } } }
Is there a way around this? Chen VenkataramanOnly the property needs to be public. Your field that stores the actual value should be marked private. You want WSDL to ignore it and only pay attention to the public property. After all, why include values for both _id and Id, which actually are the same object? If you want more control over the WSDL that's generated, see the attributes in the
System.Xml.Serialization
namespace, as well as those in theSystem.Web.Services
andSystem.Web.Services.Protocols
namespaces. There is plenty of documentation about these in the .NET Framework SDK. Besides, remember that the Web Service is just another class that code can call via a proxy. Classes can only access public members of other classes unless they're derived from that class. This is how code access is supposed to work.Microsoft MVP, Visual C# My Articles
-
After playing with XML Web Services a little bit, it looks like all the data members of any custom object that need to be serialized across should be marked as public. This seems so non O-Oish or is this a limitation of the WSDL that gets generated automatically that it only supports public data members. For e.g.
[Serializable] public class SomeData { public string _id; // if this is marked private, WSDL ignores it public string Id { get { return _id; } } }
Is there a way around this? Chen VenkataramanXML Serialization only serializes public data. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpovrSerializingObjects.asp Chen Venkataraman wrote: Is there a way around this? Yes http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemRuntimeSerializationISerializableClassTopic.asp Or you can do a binary serialization to a MemoryStream and send it as a byte array. I have used this method successfully with an intermediate compression/encryption pass.