创建 WCF 代理时数据协定未标记为可序列化
Data Contract not marked as serializable while creating WCF proxy
我已将我的数据合同标记为可序列化,下面附上我的示例代码:
Imports System
Imports System.Runtime.Serialization
Imports System.Xml
Imports System.Xml.Serialization
<DataContract()>
<Serializable()>
Public Class USR_USER_CONTRACT
<DataMember()>
Public Property USR_USERID() As Global.System.String
<DataMember()>
Public Property USR_LOGINID() As Global.System.String
End Class
创建 WCF 代理后 class 我的数据协定未标记为可序列化,如下所示:
<System.Diagnostics.DebuggerStepThroughAttribute(),
System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0"),
System.Runtime.Serialization.DataContractAttribute(Name:="USR_USER_CONTRACT", [Namespace]:="http://schemas.datacontract.org/2004/07/Ebix.Evolution.EntityContract")>
Partial Public Class USR_USER_CONTRACT
Inherits Object
Implements System.Runtime.Serialization.IExtensibleDataObject
Private extensionDataField As System.Runtime.Serialization.ExtensionDataObject
Private CLM_BUDGETTIMEField As System.Nullable(Of Short)
Private PropertyUSR_DEFAULTASSFILESField As String
请帮忙。
谢谢
在WCF中,默认的class可以被DataContractSerializer
序列化。因此,不需要用Serializable
属性修饰class。通常,有两种方法可以在 WCF 中序列化一个 class。一种是DataContractSerializer
,它要求数据class用DataContract
修饰或不修饰。另一种是XML序列化器,它需要我们在Operation Contract
或ServiceContract
上添加XmlSerializerFormatAttribute
,然后我们可以使用XMLAttribute/XMlElementAttribute
来控制序列化。
[ServiceContract,XmlSerializerFormat]
public interface IService
{
[OperationContract]
string Test(Product p);
}
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
}
请参考官方文档
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/using-the-xmlserializer-class
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/using-data-contracts
如果有什么我可以帮忙的,请随时告诉我。
我已将我的数据合同标记为可序列化,下面附上我的示例代码:
Imports System
Imports System.Runtime.Serialization
Imports System.Xml
Imports System.Xml.Serialization
<DataContract()>
<Serializable()>
Public Class USR_USER_CONTRACT
<DataMember()>
Public Property USR_USERID() As Global.System.String
<DataMember()>
Public Property USR_LOGINID() As Global.System.String
End Class
创建 WCF 代理后 class 我的数据协定未标记为可序列化,如下所示:
<System.Diagnostics.DebuggerStepThroughAttribute(),
System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0"),
System.Runtime.Serialization.DataContractAttribute(Name:="USR_USER_CONTRACT", [Namespace]:="http://schemas.datacontract.org/2004/07/Ebix.Evolution.EntityContract")>
Partial Public Class USR_USER_CONTRACT
Inherits Object
Implements System.Runtime.Serialization.IExtensibleDataObject
Private extensionDataField As System.Runtime.Serialization.ExtensionDataObject
Private CLM_BUDGETTIMEField As System.Nullable(Of Short)
Private PropertyUSR_DEFAULTASSFILESField As String
请帮忙。
谢谢
在WCF中,默认的class可以被DataContractSerializer
序列化。因此,不需要用Serializable
属性修饰class。通常,有两种方法可以在 WCF 中序列化一个 class。一种是DataContractSerializer
,它要求数据class用DataContract
修饰或不修饰。另一种是XML序列化器,它需要我们在Operation Contract
或ServiceContract
上添加XmlSerializerFormatAttribute
,然后我们可以使用XMLAttribute/XMlElementAttribute
来控制序列化。
[ServiceContract,XmlSerializerFormat]
public interface IService
{
[OperationContract]
string Test(Product p);
}
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
}
请参考官方文档
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/using-the-xmlserializer-class
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/using-data-contracts
如果有什么我可以帮忙的,请随时告诉我。