【发布时间】:2020-06-20 16:10:55
【问题描述】:
我有一个从 .NET Web 服务返回的 XML 响应。用于返回响应的 API 是一个序列化响应,它去掉了 XML 的补充部分,因为它不是我无法在 API 中更改的序列化类堆栈的一部分。有没有办法获取原始 XML 响应,以便我可以返回我的响应消息的补充:补充数据部分,或者以某种方式自行获取补充:补充数据 XML 部分?
服务 API 调用是 TestPort.TestPortType response = service.GetTestPortList() 并且返回的响应不包含补充部分,因为它不是 TestPort.TestResponse 堆栈的一部分。
这是通过 Fiddle Analyzer 返回的原始 XML 消息:
<TestResponse xmlns="urn:oasis:names:tc:legalxml-filing:schema:xsd:TestResponse-4.0" xmlns:org="urn:org:ecf:extensions:Common" xmlns:j="http://niem.tech/niem/domains/jxdm/4.0" xmlns:s="http://niem.tech/niem/structures/2.0" xmlns:nc="http://niem.tech/niem/niem-core/2.0" xmlns:ecf="urn:oasis:names:tc:legalxml-filing:schema:xsd:CommonTypes-4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ecf:Error>
<ecf:ErrorCode>0</ecf:ErrorCode>
<ecf:ErrorText>No Error</ecf:ErrorText>
</ecf:Error>
<supplemental:supplementalData xmlns:supplemental="urn:oasis:names:tc:legalxml-filing:schema:xsd:supplementalData-4.0">
<nc:TestID>DATest159647</nc:TestID>
</supplemental:supplementalData>
</TestResponse>
这是从 API 返回的 XML 消息,它是一个序列化响应,因此由于补充:supplementalData 部分不是序列化响应的一部分,因此将被忽略。
<TestResponse xmlns="urn:oasis:names:tc:legalxml-filing:schema:xsd:TestResponse-4.0" xmlns:org="urn:org:ecf:extensions:Common" xmlns:j="http://niem.tech/niem/domains/jxdm/4.0" xmlns:s="http://niem.tech/niem/structures/2.0" xmlns:nc="http://niem.tech/niem/niem-core/2.0" xmlns:ecf="urn:oasis:names:tc:legalxml-filing:schema:xsd:CommonTypes-4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ecf:Error>
<ecf:ErrorCode>0</ecf:ErrorCode>
<ecf:ErrorText>No Error</ecf:ErrorText>
</ecf:Error>
</TestResponse>
这是我在返回响应后尝试从我的 .Net 托管应用程序中访问的 XML 部分,但它正在从返回的序列化响应中删除。
<supplemental:supplementalData xmlns:supplemental="urn:oasis:names:tc:legalxml-filing:schema:xsd:supplementalData-4.0">
<nc:TestID>DATest159647</nc:TestID>
</supplemental:supplementalData>
【问题讨论】:
-
Web 服务是 WCF 吗?如果是WCF,可以通过IDispatchMessageInspector截取消息,得到原始的XML部分。关于IDispatchMessageInspector的更多信息,请参考以下链接:docs.microsoft.com/en-us/dotnet/api/…
-
是的,Web 服务是 WCF 服务,我正在托管 WCF 服务。在我这边,服务主机部分是一个调用 API 方法。我可以在服务的托管控制台部分使用 IDispatchMessageInspector,还是只能在应用程序本身的服务端使用。 IDispatchMessageInspector 是否易于实现以仅获取原始 xml 响应?
-
如何将 IDispatchMessageInspector 包裹在 API 调用方法周围以获取 xml 响应?