开发者

Serialize a System.Type from WCF service and deserialize from Silverlight client?

开发者 https://www.devze.com 2023-02-28 17:17 出处:网络
I am trying to accomplish the task of sending an instance of System.Type from a WCF REST JSON service to a Silverlight client. A开发者_开发知识库lthough System.Type is marked as Serializable, my WCF s

I am trying to accomplish the task of sending an instance of System.Type from a WCF REST JSON service to a Silverlight client. A开发者_开发知识库lthough System.Type is marked as Serializable, my WCF service responds with a server error if I attempt to have my OperationContract method implementation return a System.Type. For example,

[OperationContract]
        [WebInvoke(Method = "GET",
                    ResponseFormat = WebMessageFormat.Json,
                    UriTemplate = "type")]
        public Type getType()
        {
            return typeof(string);
            //request error: The server encountered an error processing the request. See server logs for more details.
        }

I haven't gotten serialization of a System.Type to work with System.Web.Script.Serialization.JavaScriptSerializer or DataContractSerializer either. I have only gotten serialization to work with BinaryFormatter. The problem is, that Silverlight 4 doesn't have BinaryFormatter. I have found this Silverlight binary serialization library, which looks promising but hasn't succeeded in serializing a System.Type.

Does anyone have any ideas on how to serialize a System.Type from a WCF service and then deserialize it from Silverlight? A code snippet sample of a working solution would be helpful and appreciated.


Type is not usable in the fashion described (and note that [Serializable] only really applies to BinaryFormatter). Your best bet is to transport the AssemblyQualifiedName and load at each end, but note that you will need the declaring assembly at each end for this to work.

Ultimately the objective of sending a Type between platforms doesn't really make much sense, I'm adraid. If you could be more specific a out what you want to accomplish maybe we can suggest a better plan?

0

精彩评论

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