我有一个.net 4.0 Framework WCF服务。我将此WCF引用到.NET Framework 2.0网站(不是Web应用程序,只是一个网站)。
但是当我调用WCF的方法时,我得到一个例外:
There was an error generating the XML document.
内部异常是:
System.Uri无法序列化,因为它没有无参数构造函数。
我有一个无参数的consturctor和我在WCF中继承的那个,如下所示:
//Service Class
public class MyWcfService : IWcfService
{
//I even put this hoping to make it work
public MyWcfService()
{
}
public MyEntity GetEntity(ArgumentObject arg)
{
return DoGetMyEntity(arg);
}
}
[Serializable]
public class MyEntity : EntityBase
{
public DateTime LastUpdate { set; get; }
//Here is the parameterless constructor
public MsisdnInformation()
{
this.LastUpdate = DateTime.Now;
}
}
[Serializable]
public class EntityBase
{
//Here is the parameterless constructor
public EntityBase()
{
}
}
此WCF正在与其他项目合作(但这些项目是.NET 3.0或更高版本的框架项目。其中一些项目是网站,其中一些项目是WepApplication。
到目前为止,在我的网络搜索中,我找不到任何可以帮助我的案子。
我需要做些什么才能解决此错误?
答案 0 :(得分:3)
正如约翰·桑德斯在评论我的问题时指出的那样,我需要改变
httpContext.Request.Url
到
httpContext.Request.Url.ToString()
为了传递
System.Uri
从.NET 2.0 Framework到WCF的参数。
我有点尴尬,我忽略了这个参数。
答案 1 :(得分:2)
使用DataContract而不是Serializable。这意味着序列化将由DataContractSerializer处理。
DataContract(和DataMember)属性取代Serializable属性。