当它与F#编码中的类型实例ident和直接属性成员一起使用时,在WCF主机中运行它,并从客户端调用它,错误发生如下
System.InvalidOperationException:尝试反序列化参数http://tempuri.org/时出错:....有关详细信息,请参阅InnerException。 ---> System.InvalidOperationException:对象的初始化或 value导致在完全初始化之前递归访问对象或值
[<DataContract>]
type A()=
[<DefaultValue>] val mutable _Column:DateTime
[<DataMember>]
member x.Column
with get ()=x._Column
and set v=x._Column<-v
//===============================================
//***1.***
//It's wrong with type instance ident and direct property members
//Use without 'DefaultValue'
[<Sealed>]
[<DataContract>]
type B=
inherit A
val mutable _ColumnA:DateTime
new ()={inherit A();_ColumnA=DateTime.Now}
new (para) as x=new B() then //Type instance ident is 'x'
do
x.Initialize ()
member x.Initialize ()=
"TODO" |>ignore
[<DataMember>] //the type have direct property members
member x.ColumnA
with get ()=x._ColumnA
and set v=x._ColumnA<-v //The error will occurs in this position, 'The initialization of an object or value resulted in an object or value being accessed recursively before it was fully initialized'
//===============================================
//***2.***
(*
//It's wrong with type instance ident and direct property members
//Use with 'DefaultValue'
[<Sealed>]
[<DataContract>]
type B=
inherit A
new ()={inherit A()}
new (para) as x=new B() then //Type instance ident is 'x'
do
x.Initialize ()
x.ColumnA<-DateTime.Now
member x.Initialize ()=
"TODO" |>ignore
[<DefaultValue>] val mutable _ColumnA:DateTime //Use with 'DefaultValue'
[<DataMember>] //the type have direct property members
member x.ColumnA
with get ()=x._ColumnA
and set v=x._ColumnA<-v //The error will occurs in this position, 'The initialization of an object or value resulted in an object or value being accessed recursively before it was fully initialized'
*)
//===============================================
//***3.***
(*
//It's right with type instance ident and without direct property members
[<Sealed>]
[<DataContract>]
type B=
inherit A
new ()={inherit A()}
new (para) as x=new B() then //Type instance ident is 'x'
do
x.Initialize ()
member x.Initialize ()=
"TODO" |>ignore
*)
//===============================================
//***4.***
(*
// it's right when it's without type instance ident!
[<Sealed>]
[<DataContract>]
type B=
inherit A
new ()={inherit A()}
new (para)=new B() then
do
"TODO" |>ignore
*)
非常感谢Brian的审核和修改。
我该如何纠正?
//------------------------------------------------------------
Addition,
namespace NS
open System
open System.ServiceModel
[<ServiceContract>]
type IService =
[<OperationContract>] abstract Query:isAsceding:bool->B[] //The parameter name 'isAsceding' is needed in WCF enviroment
namespace NS
open System
open System.ServiceModel
[<ServiceBehavior(Name="NS.Service",InstanceContextMode=InstanceContextMode.Single) >]
type Service() =
interface IService with
member x.Query isAsceding=
//TODO
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="Shared_wsHttpBinding"
closeTimeout="00:02:00"
openTimeout="00:02:00"
receiveTimeout="00:10:00"
sendTimeout="00:02:00"
bypassProxyOnLocal="false"
transactionFlow="false"
hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="52428800"
maxReceivedMessageSize="6553600"
messageEncoding="Text"
textEncoding="utf-8"
useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="3200"
maxStringContentLength="819200"
maxArrayLength="1638400"
maxBytesPerRead="409600"
maxNameTableCharCount="1638400" />
<reliableSession ordered="true"
inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows"
proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows"
negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8080/Service"
binding="wsHttpBinding"
bindingConfiguration="Shared_wsHttpBinding"
contract="NS.IService"
name="WSHttpBinding_IService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>