开发者

Serializing a .NET type from an LdapConnection

I'm having a problem in that I'm using an LdapConnection to make requests against an AD LDS (formerly known as ADAM) datastore. Fine. But now requirements have come along to be able to "remotely" do this. Basically, a program we could count on always having access to the datastore now needs to do it through a "server" program on the "internal" network, so that the "client" on the external one only communicates through our new "server" program. There's a reason (not a great one, but a reason) why we can't just expose the AD LDS server to the outside. But they want it done "fast" and thus don't want to re-engineer the client app (as should be what's really happening). Thus we 开发者_高级运维need to serialize the DataRequest and DataResponses to go to and from the "server" part.

Big problem: The DataResponses don't seem to be serializable. During testing, a DataContractSerializer has no problem serializing my SearchRequest but the SearchResponse gets this:

System.Runtime.Serialization.InvalidDataContractException occurred
  Message="Type 'System.DirectoryServices.Protocols.SearchResponse' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute.  See the Microsoft .NET Framework documentation for other supported types."
  Source="System.Runtime.Serialization"
  StackTrace:
       at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.ThrowInvalidDataContractException(String message, Type type)
  InnerException: 

OK. But neither type has Serializable or what not. So why does SearchRequest go through the process fine, and the response doesn't?

But that doesn't even matter in the end. How am I supposed to serialize a type that I can't change, as it's built-in to the .NET framework, and I can't "re-make" because the constructor is internal? If I could just "take the information I needed" and re-make the class on the other end of my network connection, I would, but these types don't have public constructors.

Any ideas? I'd even like to know why one of the types "just works" even without the right attributes for the DataContractSerializer but the other doesn't.


The best - and probably only - approach is to create your own wrapper class and then read the result and store in the class and serialise.

SearchResponse in fact is a COM wrapper and cannot be serialised.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜