相关疑难解决方法(0)

序列化接口

我正在尝试运行类似于此的代码:

using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;

namespace ConsoleApplication1
{
    [Serializable]
    [XmlInclude(typeof(List<Class2>))]
    public class Class1
    {
        private IList<Class2> myArray;

        public IList<Class2> MyArray
        {
            get { return myArray; }
            set { myArray = value; }
        }

    }

    public class Class2
    {
        private int myVar;

        public int MyProperty
        {
            get { return myVar; }
            set { myVar = value; }
        }

    }

    class Program
    {
        static void Main(string[] args)
        {
            XmlSerializer ser = new XmlSerializer(typeof(Class1), new Type[] { typeof(List<Class2>) }); …
Run Code Online (Sandbox Code Playgroud)

c# xml-serialization

11
推荐指数
3
解决办法
3万
查看次数

Wcf和接口作为参数

我有一个库,其中包含一些共享相同界面的实体.客户和服务共享此程序集.现在我想知道是否有办法在我的服务合同中将此接口类型作为参数,以便我可以对实现接口的所有类使用相同的方法.

实体itselve都使用datacontract-attribute及其成员使用datamember属性进行修饰.

它有可能吗?可能与NetDataContractSerializer?我知道我可以使用基类(一些抽象类,例如)和知识类型 - 属性,但我肯定更喜欢接口作为对象的标识符,因为它在客户端应用程序中广泛使用,并将简化开发.

谢谢

.net c# wcf web-services

6
推荐指数
1
解决办法
4875
查看次数

标签 统计

c# ×2

.net ×1

wcf ×1

web-services ×1

xml-serialization ×1