Web Service and Properties in C#
I'm quite new to Web Services. I've created a Web Serivce with a class like this:
public class ClassA
{
private ClassB _varA;
public ClassB VarA
{
get {
if(_varA == null)
_varA = new ClassB();
return _varA;
}
set { _varA = 开发者_Python百科value; }
}
}
When I try to access the property from a website, it gives me null.
using WebServiceA;
ClassA obj = new ClassA();
obj.VarA // gives me null ?
Am I missing something here? Please help. Thanks.
When you send an object over a web-service, the actual functions don't come with it, only the property values (so the get in your example doesn't actually happen client side). Instead, it creates a 'mock' type version of the same object.
I figured I'd clarify in this edit:
When you connect to a web service that returns an object, it actually just returns an XML representation of the object. This XML representation only contains data that gets serialized (method depends on the settings, in plain-jane web services, it is usually just an XML Serializer), thus does not contain any functions or property definitions.
So, the class in this example is:
public class ClassA
{
public ClassB VarA
{
get;
set;
}
}
Also: Fredrik Mörk said it correclty, its called a 'Proxy' object, not a mock object, I couldn't think of the word.
Is class B being implemented inside the project of the webservice?
精彩评论