调试不会序列化对象的WCF服务

Jas*_*ldo 7 vb.net wcf serialization json

我遇到了将对象序列化为JSON以及对WCF不熟悉的问题,我在调试方面遇到了问题.如果我通过在浏览器中键入url来点击服务,那么我得到的就是页面不可用.

场景:我有A类,它继承了B类的List.如果我在A类中注释它添加到它的集合中,我至少可以点击该服务(显然没有数据存在),但是如果它添加到它的集合中,我就再也无法点击该服务了.

接口:

<OperationContract()> _
<WebGet(UriTemplate:="getAdverseReactions", responseFormat:=WebMessageFormat.Json)> _
<ServiceKnownType(GetType(AdverseReactions))> _
<ServiceKnownType(GetType(AdverseReaction))> _
Function GetAdverseReactions() As AdverseReactions
Run Code Online (Sandbox Code Playgroud)

实现界面:

Public Function GetAdverseReactions() As AdverseReactions Implements IPortalCoreService.GetAdverseReactions
    Return CoreServiceController.GetAdverseReactions()//which returns class A
End Function
Run Code Online (Sandbox Code Playgroud)

A类:

<CollectionDataContract(Name:="AdverseReactionsCollection", ItemName:="AdverseReaction")> _
Public Class AdverseReactions
Inherits List(Of AdverseReaction)
Run Code Online (Sandbox Code Playgroud)

B级:

<DataContract(IsReference:=True)> _
Public Class AdverseReaction
Run Code Online (Sandbox Code Playgroud)

我通过附加一个进程来执行代码,并且没有抛出任何异常,我可以确认对象是按原样返回的,我显然无法序列化它.我读过有关循环引用的内容,我的一位朋友建议这两个类可能以无限的方式相互序列化.

我的主要问题:是否有一个地方我可以看看为什么会发生这种情况,或至少有一些关于它的信息?这个问题一直在处理我,我想要的是序列化这个,当我这样做时,我想我会休假一周:).

com*_*ech 11

将以下块添加到web.config <configuration>

  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel"
              switchValue="Information, ActivityTracing"
              propagateActivity="true">
        <listeners>
          <add name="traceListener"
              type="System.Diagnostics.XmlWriterTraceListener"
              initializeData="c:\log\WebTrace.svclog"  />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
Run Code Online (Sandbox Code Playgroud)

并确保指定的目录(c:\ log)存在且可由IIS服务写入.

完成此操作后,执行导致序列化问题的操作,然后导航到该目录并双击生成的svclog文件.

这将在Microsoft服务跟踪查看器中打开该文件.打开后,您将看到左侧红色显示的错误.

单击其中一个将在右上方窗格中显示详细信息,您可以单击每个操作以确定WCF正在抱怨的内容.