Webservice 接口 如下:
[WebMethod]
public void SetCacheValue(string key, object value)
{
Cache.Insert(key,value);
}在客户端有如下的调用:
WebserviceInterface.ClassName i = new WebserviceInterface.ClassName();
ClassEntityA entityA = new ClassEntityA();
entityA.strA = "a";
ClassEntityB entityB = new ClassEntityB();
entityB .intA = 205;
ClassEntityC entityC = new ClassEntityC();
entityC .floatA = 1.25;
i.SetCacheValue("key1",entityA);
i.SetCacheValue("key2",entityB);
i.SetCacheValue("key3",entityC);public class ClassEntityA()
{
public string strA ;
}
public class ClassEntityB()
{
public int intA;
}
public class ClassEntityC()
{
public float floatA;
}
怎么在保证调用同一个webservice的接口时,序列化自定义类参数呀.
大伙帮帮忙呀!
[WebMethod]
public void SetCacheValue(string key, object value)
{
Cache.Insert(key,value);
}在客户端有如下的调用:
WebserviceInterface.ClassName i = new WebserviceInterface.ClassName();
ClassEntityA entityA = new ClassEntityA();
entityA.strA = "a";
ClassEntityB entityB = new ClassEntityB();
entityB .intA = 205;
ClassEntityC entityC = new ClassEntityC();
entityC .floatA = 1.25;
i.SetCacheValue("key1",entityA);
i.SetCacheValue("key2",entityB);
i.SetCacheValue("key3",entityC);public class ClassEntityA()
{
public string strA ;
}
public class ClassEntityB()
{
public int intA;
}
public class ClassEntityC()
{
public float floatA;
}
怎么在保证调用同一个webservice的接口时,序列化自定义类参数呀.
大伙帮帮忙呀!
解决方案 »
- 关于数据库连接的问题
- 问一下,winform(C#),关于多线程,定时执行的问题……(豁出所有分)大家来看看吧
- winform 右下角弹出消息
- 关闭线程问题
- 在应用程序中,如何将ListView控件中选中的项生成DataSet形式
- datagridview DataGridViewCheckBoxColumn列选中的值能不能转化数库中如'y','n'
- C# WinFrom设置背景图片显示问题!!
- 关于buttoncolumn的问题。
- 冥思苦索,终不得解之三!(关于VS.Net beta2与QQ发生冲突的问题)
- c#不会有~~~~~!
- .NET Compact Framework 下容器控件问题
- system.timers.timer数组多事件的问题
请考虑使用 DataContractResolver,或将任何未知类型以静态方式添加到已知类型的列表。例如,可以使用 KnownTypeAttribute 特性,或者将未知类型添加到传递给 DataContractSerializer 的已知类型列表。 出现这样的而错误是什么原因呀?
服务端也引用了这个命名空间!
我的Webservice也创建在同一样项目内!
Webservice的方法上的object value参数,可以是接受的客户端的 ClassEntityA 或者是 ClassEntityB 或者是 ClassEntityC
那怎么办???????
AllowMultiple = true)]
public sealed class KnownTypeAttribute : Attribute
然后 用KnownType[DataContract]
[KnownType(typeof(ClassEntityA ))
[KnownType(typeof(ClassEntityB ))
[KnownType(typeof(ClassEntityC ))
class BaseClass
{
}
[DataContract]
class ClassEntityA : BaseClass
{..}
[DataContract]
class ClassEntityB : BaseClass
{..}
[DataContract]
class ClassEntityC : BaseClass
{..}然后函数声明的时候就可以使用基类了public void SetCacheValue(string key, BaseClass value)
以上代码没有经过编译及测试,可能有些许错误。