以下类的对象需要作为参数传递给 WCF Web 服务:
public class Context
{
public static readonly string AUTH_CODE = "AUTH_CODE";
public static readonly string REQUEST_TAG = "REQUEST_TAG";
private readonly IDictionary<string, string> _context = new Dictionary<string, string>();
public void AddProperty(string key, string value)
{
_context.Add(key, value);
}
public string GetProperty(string name)
{
return _context[name];
}
}
我用 [DataContract] 和 AUTH_CODE、REQUEST_TAG 和 _context 字段用 [DataMember] 标记了类。类本身与服务器端的 Web 服务一起定义。
当我尝试实例化此类的对象以便在从客户端调用 Web 服务时将其作为参数传递时,我观察到以下情况:
- AUTH_CODE 和 REQUEST_TAG 不可见。
- _context 是可见的,虽然它是一个私人成员
- AddProperty 和 GetProperty 方法不可见
你能解释一下上述行为吗?
此外,在调用 Web 服务之前,我需要访问 AddProperty 方法来填充对象。我如何实现这一目标?
注意:这是我第一次使用 WCF。如果我偏离了实现此类行为的任何标准做法,请告知。