如何获得传递到Web服务对象的序列化XML?如何获得、对象、序列化、XML

2023-09-06 15:53:55 作者:时光带走好多狗

我有一个使用Web服务的一个VB.NET(2008)控制台应用程序。所有工作正常 - 我用WSDL.EXE导入Web服务的定义,并建立相应的课程,我可以用这些类进行交互,以填​​补他们与数据,并调用Web服务成功和数据传递

I have a VB.NET (2008) console application which consumes a web service. All is working fine -- I've used WSDL.exe to import the web service's definition and create the appropriate classes, I can interact with those classes to fill them up with data, and the call to the web service succeeds and data is passed.

不过,数据传输成功后,我想我的Oracle数据库中记录此事件表 - 包括被转移(审查在以后的XML,万一有关于特定问题这是通过数据等)。我怎么可以得到通过这些对象的序列化自动创建的XML(由.NET内部管道)?

However, after the successful transfer of data, I would like to log this event to a table in my Oracle database -- including the XML that was transferred (for review at a later time, in case there are questions about the specific data which was passed, etc.). How can I get the XML that was created through the automatic serialization of these objects (by the .NET internal plumbing)?

我可以序列化的对象,自己和获得的近似的再presentation数据,例如:

I can serialize the objects myself and get an approximate representation of the data, for example:

Dim oStringBuilder As New StringBuilder
Dim oStringWriter As New StringWriter(oStringBuilder)
Dim oXmlTextWriter As New XmlTextWriter(oStringWriter)

'-- (oData, for the purposes of this example, is an instance of the main data class explosed in the code generated by WSDL.exe)
Dim oXmlSerializer as New System.Xml.Serialization.XmlSerializer(oData.GetType)

'-- Serialize the data to a StringBuilder
oXmlTextWriter.Formatting = Formatting.Indented
oXmlSerializer.Serialize(oXmlTextWriter, oData)

'-- Display serialized XML (in practice this would be an insert to a table, etc.)
MessageBox.Show(oStringBuilder.ToString)

...然而,这确实是不一样的究竟获取传递到web服务(最值得注意的是,某些元素名称是不同的,它不包括相同的头信息,并根元素) 。有教学班,Serialization.XmlTypeAttribute定义等,我假设正在使用的.NET框架做处理真正的SOAP管道。我怎样才能获得的实际的传递到Web服务,XML?

... however, this really isn't the same as what actually gets passed to the web service (most notably, some of the element names are different, and it doesn't include the same header information and root elements). There are classes with Serialization.XmlTypeAttribute definitions, etc., which I assume are being used by the .NET framework to do handle the real SOAP plumbing. How can I get the actual XML that is passed to the web service?

推荐答案

如果你没有选择,只能使用旧的ASMX技术(WSDL.EXE,添加Web引用),那么你应该使用的的SoapExtension 来记录你的服务请求和响应。

If you have no choice other than to use the legacy ASMX technology (WSDL.EXE, "Add Web Reference"), then you should use a SoapExtension to log your service requests and responses.