查看原始XML请求

dav*_*ave 5 .net wcf soap web-services

我是WCF和SOAP消息的新手,但我已经设法组建了一个相当不错的客户端,我用它来从媒体组织下载新闻报道.我已经生成了很明显抽象的代理类,这意味着我基本上只是创建对象,调用方法和迭代结果.

我的问题是我有关于Web服务调用应该是什么样子的原始XML示例,我希望能够将这些调用与我正在进行的调用进行"比较".基本上我需要确保我正在进行的调用与用于测试目的的示例XML文件相同.

我所要求的是有意义还是我以错误的方式解决这个问题?如果我遗漏了任何必要的信息,请告诉我,我可以为段落敲打,但不确定哪些信息是相关的.

Dan*_*llo 10

您可以使用WCF跟踪来记录原始XML消息.以下是.config使用原始消息日志记录启用WCF跟踪:

<configuration>
  <system.serviceModel>
    <diagnostics>
      <messageLogging maxMessagesToLog="30000"
              logEntireMessage="true"
              logMessagesAtServiceLevel="true"
              logMalformedMessages="true"
              logMessagesAtTransportLevel="true">
      </messageLogging>
    </diagnostics>
  </system.serviceModel>
  <system.diagnostics>
    <sources>
      <source name="System.IdentityModel" switchValue="Verbose" logKnownPii="true">
        <listeners>
          <add name="xml" />
        </listeners>
      </source>
      <!-- Log all messages in the 'Messages' tab of SvcTraceViewer. -->
      <source name="System.ServiceModel.MessageLogging">
        <listeners>
          <add name="xml" />
        </listeners>
      </source>
      <!-- ActivityTracing and propogateActivity are used to flesh out the 'Activities' tab in
           SvcTraceViewer to aid debugging. -->
      <source name="System.ServiceModel" switchValue="Error, ActivityTracing" propagateActivity="true">
        <listeners>
          <add name="xml" />
        </listeners>
      </source>
      <!-- This records Microsoft.IdentityModel generated traces, including exceptions thrown
           from the framework. -->
      <source name="Microsoft.IdentityModel" switchValue="Warning">
        <listeners>
          <add name="xml" />
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="trace.e2e" />
    </sharedListeners>
    <trace autoflush="true" />
  </system.diagnostics>
</configuration>
Run Code Online (Sandbox Code Playgroud)

您可以从MSDN中了解有关WCF跟踪的更多信息:配置跟踪.

Microsoft提供了一个服务跟踪查看器工具来读取.svclog文件.

确保initializeData您的服务可以写入定义的路径.


slu*_*ter 2

您使用过 Microsoft 的 Service Trace Viewer 工具吗?此 MSDN 页面将为您提供有关如何使用它的详细信息。