oracle input =>,使用 WCF 通道模型流式传输 Oracle Database LOB 数据类型

使用 WCF 通道模型流式传输 Oracle Database LOB 数据类型Streaming Oracle Database LOB Data Types Using the WCF Channel Model

06/08/2017

本文内容

用于 Oracle 数据库的 Microsoft BizTalk 适配器Microsoft BizTalk Adapter for Oracle Database支持特定操作的 LOB 数据的端到端流式处理。The 用于 Oracle 数据库的 Microsoft BizTalk 适配器Microsoft BizTalk Adapter for Oracle Database supports end-to-end streaming of LOB data for certain operations. 本主题中的部分介绍了在使用 WCF 通道模型时如何为 LOB 数据实现流式处理。The sections in this topic describe how to implement streaming for LOB data when you use the WCF channel model.

有关适配器如何支持对 LOB 数据类型进行流式处理的背景信息,请参阅 在 Oracle Database 适配器中流式传输大型对象数据类型。For background information about how the adapter supports streaming of LOB data types, see Streaming large object data types in Oracle Database adapter. 在继续操作之前,应阅读本主题。You should read this topic before proceeding.

示例演示了如何在随附的 SDK 示例中使用 LOB 数据流 Oracle 数据库适配器Oracle Database adapter 。A sample that demonstrates LOB data streaming is available in the SDK samples included with the Oracle 数据库适配器Oracle Database adapter. 有关详细信息,请参阅 SDK 中的示例。For more information, see Samples in the SDK.

将出站消息流式传输到适配器Streaming Outbound Messages to the Adapter

适配器支持 UpdateLOB 操作的请求消息的端到端 LOB 数据流。The adapter supports end-to-end LOB data streaming for the request message for the UpdateLOB operation.

若要支持 WCF 通道模型中 UpdateLOB 操作的端到端流式处理,必须执行以下操作:To support end-to-end streaming on UpdateLOB operations in the WCF channel model, you must:

将 UseAmbientTransaction 绑定属性设置为 true。Set the UseAmbientTransaction binding property to true.

实现 BodyWriter ,它能够流式传输 lob 数据, (在 lob 数据) 上执行节点值流式处理。Implement a System.ServiceModel.Channels.BodyWriter that is capable of streaming the LOB data (performing node-value streaming on the LOB data).

在事务范围内执行 UpdateLOB 操作。Perform the UpdateLOB operation within a transaction scope.

使用消息的适当重载通过此 BodyWriter 提供消息正文来创建用于调用操作的 system.servicemodel。 create 方法。Create the System.ServiceModel.Message used to invoke the operation by supplying the message body with this BodyWriter using an appropriate overload of the Message.Create method.

设置 UseAmbientTransaction 绑定属性Setting the UseAmbientTransaction Binding Property

下面的示例演示如何为创建绑定 Oracle 数据库适配器Oracle Database adapter 并设置 UseAmbientTransaction 绑定属性。The following example shows how to create a binding for the Oracle 数据库适配器Oracle Database adapter and set the UseAmbientTransaction binding property.

// Create binding

OracleDBBinding odbBinding = new OracleDBBinding();

//set the binding property

binding.UseAmbientTransaction = true;

实现 BodyWriterImplementing a BodyWriter

下面的示例演示执行节点值流式处理的 BodyWriter 实现。The following example shows an implementation of a BodyWriter that performs node-value streaming.

///

/// This class overrides the OnWriteBodyContents function to do node-value streaming

///

class StreamingBodyWriter : BodyWriter, IDisposable

{

XmlReader m_reader = null;

int m_chunkSize;

///

/// Initializes the body writer

///

/// Reader for input

/// The chunksize in which the data is passed to adapter

public StreamingBodyWriter(XmlReader reader, int chunkSize)

: base(false)

{

m_reader = reader;

if (chunkSize \<= 0)

throw new ApplicationException("ChunkSize should be a positive value");

m_chunkSize = chunkSize;

}

protected override void OnWriteBodyContents(XmlDictionaryWriter writer)

{

if (m_reader == null)

throw new ApplicationException("Reader cannot be null");

while (m_reader.Read())

{

switch (m_reader.NodeType)

{

case XmlNodeType.Element:

writer.WriteStartElement(m_reader.LocalName, m_reader.NamespaceURI);

break;

case XmlNodeType.Text:

#region Streaming Code

char[] tempBuffer = new char[m_chunkSize];

int length = 0;

while ((length = m_reader.ReadValueChunk(tempBuffer, 0, m_chunkSize)) > 0)

{

writer.WriteString(new String(tempBuffer, 0, length));

}

#endregion

break;

case XmlNodeType.EndElement:

writer.WriteEndElement();

break;

}

}

}

#region IDisposable Members

public void Dispose()

{

if (m_reader != null)

{

m_reader.Close();

m_reader = null;

}

}

#endregion

}

在事务范围内执行操作Perform the Operations Within a Transaction Scope

下面的示例演示如何在事务范围内执行操作。The following example shows how to perform operations within a transaction scope.

// Create a transaction scope

using(TransactionScope tx = new TransactionScope())

{

// perform operations within the transaction

// ...

// ...

//Complete the transaction

tx.Complete()

}

使用 BodyWriter 创建消息Creating a Message by using a BodyWriter

下面的示例演示如何使用前面示例中的 BodyWriter 创建 UpdateLOB 请求消息。The following example shows how to create an UpdateLOB request message using the BodyWriter in the preceding example. 消息数据是从文件中读取的。The message data is read from a file.

// Create a transaction scope

using(TransactionScope tx = new TransactionScope())

{

XmlReader readerIn = XmlReader.Create ("updatelob.xml");

// StreamingBodyWrtier class is responsible for streaming

StreamingBodyWriter stBW = new StreamingBodyWriter(readerIn, chunkSize);

Message InputMsg = Message.CreateMessage(MessageVersion.Default,

"http://Microsoft.LobServices.OracleDB/2007/03/SCOTT/Table/CUSTOMER/UpdateLOB",

stBW);

//Send the request message and get the output message

OutputMsg = channel.Request(InputMsg);

tx.Complete();

}

从适配器流式传输入站消息Streaming Inbound Messages from the Adapter

适配器支持以下入站消息的端到端 LOB 数据流:The adapter supports end-to-end LOB data streaming for the following inbound messages:

带有 OUT 或 OUT 参数的函数的响应消息,其中包含 LOB 数据。Response message for functions with OUT or IN OUT parameters that contain LOB data. 请注意,记录类型参数可包含 LOB 数据列。Note that RECORD TYPE parameters can contain LOB data columns.

带有 OUT 引用游标参数 (或返回值) 包含 LOB 数据的函数的响应消息。Response message for functions with OUT REF CURSOR parameters (or return values) that contain LOB data. 这包括输出侧的 OUT 引用 CURSOR 参数。This includes the output side of IN OUT REF CURSOR parameters.

包含 LOB 数据的 IN 或 OUT 参数中的过程的响应消息。Response message for procedures with IN or IN OUT parameters that contain LOB data. 请注意,记录类型参数可包含 LOB 数据列。Note that RECORD TYPE parameters can contain LOB data columns.

带有 OUT 引用 CURSOR 参数的过程的响应消息,其中包含 LOB 数据。Response message for procedures with OUT REF CURSOR parameters that contain LOB data. 这包括中的输出端 IN OUT REF CURSOR 参数This includes the output side of IN OUT REF CURSOR parameters

返回包含 LOB 数据的结果集的 SQLEXECUTE 操作的响应消息。Response message for SQLEXECUTE operations that return result sets that contain LOB data.

表或视图的响应消息选择在结果集中返回 LOB 数据的操作。Response message for Table or view Select operations that return LOB data in the result set.

(入站) POLLINGSTMT 操作的请求消息Request message for the (inbound) POLLINGSTMT operation

若要支持 WCF 通道模型中入站消息的端到端流式处理,必须执行以下操作:To support end-to-end streaming on an inbound message in the WCF channel model, you must:

实现一个 System.Xml.XmlDictionaryWriter ,它能够在 lob 数据) 上执行节点-值流式处理 (流式传输 lob 数据。Implement a System.Xml.XmlDictionaryWriter that is capable of streaming the LOB data (performing node-value streaming on the LOB data).

通过使用此 XmlDictionaryWriter 调用 WriteBodyContents 方法来使用 消息。Consume the Message by invoking WriteBodyContents method with this XmlDictionaryWriter.

实现 XmlDictionaryWriterImplementing an XmlDictionaryWriter

下面的示例演示执行节点值流式处理的 XmlDictionaryWriter 实现。The following example shows an implementation of an XmlDictionaryWriter that performs node-value streaming.

using System;

using System.Xml;

using System.Text;

class FileXmlWriter : XmlDictionaryWriter

{

XmlTextWriter xts;

public FileXmlWriter(string file)

{

xts = new XmlTextWriter(file, Encoding.UTF8);

}

public override void WriteBase64(byte[] buffer, int index, int count)

{

xts.WriteBase64(buffer, index, count);

}

public override void WriteCData(string text)

{

xts.WriteCData(text);

}

public override void WriteCharEntity(char ch)

{

xts.WriteCharEntity(ch);

}

public override void WriteChars(char[] buffer, int index, int count)

{

xts.WriteChars(buffer, index, count);

}

public override void WriteComment(string text)

{

xts.WriteComment(text);

}

public override void WriteDocType(string name, string pubid, string sysid, string subset)

{

xts.WriteDocType(name, pubid, sysid, subset);

}

public override void WriteEndAttribute()

{

xts.WriteEndAttribute();

}

public override void WriteEndDocument()

{

xts.WriteEndDocument();

}

public override void WriteEndElement()

{

xts.WriteEndElement();

}

public override void WriteEntityRef(string name)

{

xts.WriteEntityRef(name);

}

public override void WriteFullEndElement()

{

xts.WriteFullEndElement();

}

public override void WriteProcessingInstruction(string name, string text)

{

xts.WriteProcessingInstruction(name, text);

}

public override void WriteRaw(string data)

{

xts.WriteRaw(data);

}

public override void WriteRaw(char[] buffer, int index, int count)

{

xts.WriteRaw(buffer, index, count);

}

public override void WriteStartAttribute(string prefix, string localName, string ns)

{

xts.WriteStartAttribute(prefix, localName, ns);

}

public override void WriteStartDocument(bool standalone)

{

xts.WriteStartDocument(standalone);

}

public override void WriteStartDocument()

{

xts.WriteStartDocument();

}

public override void WriteStartElement(string prefix, string localName, string ns)

{

xts.WriteStartElement(localName);

}

public override void WriteString(string text)

{

xts.WriteString(text);

}

public override void WriteSurrogateCharEntity(char lowChar, char highChar)

{

xts.WriteSurrogateCharEntity(lowChar, highChar);

}

public override void WriteWhitespace(string ws)

{

xts.WriteWhitespace(ws);

}

public override void Close()

{

xts.Close();

}

public override void Flush()

{

xts.Flush();

}

public override string LookupPrefix(string ns)

{

return xts.LookupPrefix(ns);

}

public override WriteState WriteState

{

get { return xts.WriteState; }

}

}

使用 XmlDictionaryWriter 来使用消息Consuming a Message by using an XmlDictionaryWriter

下面的示例演示如何使用在前面的示例中实现的 FileXmlWriter 的表选择响应消息。The following example shows how to consume a table Select response message using the FileXmlWriter implemented in the preceding example. (FileWriter 类是由分类 XmlDictionaryWriter 创建的。 ) 该示例使用 IRequestChannel 通道调用选择操作。(The FileWriter class was created by sub-classing XmlDictionaryWriter.) The example uses an IRequestChannel channel to invoke the Select operation. 已省略通道创建的详细信息。The details of the channel creation have been omitted. 将从文件中读取 Select 请求消息,并将选择响应消息写入文件。The Select request message is read from a file and the Select response message is written to a file.

// Read Select message body from a file

XmlReader readerIn = XmlReader.Create("select.xml");

Message InputMsg = Message.CreateMessage(MessageVersion.Default,

"http://Microsoft.LobServices.OracleDB/2007/03/SCOTT/Table/CUSTOMER/Select", readerIn);

Message OutputMsg = channel.Request(InputMsg);

// Streaming response message to select_output.xml using the custom XmlDictionaryWriter;

FileXmlWriter fileXmlWriter = new FileXmlWriter("select_output.xml");

OutputMsg.WriteBodyContents(fileXmlWriter);

fileXmlWriter.Flush();

fileXmlWriter.Close();

// Streaming complete close output message;

OutputMsg.Close();

下面的 XML 显示了 (select.xml 文件的内容的请求消息) 用于选择操作。The following XML shows the request message (contents of the select.xml file) for the Select operation. CUSTOMER 表包含名为 PHOTO 的 BLOB 列。The CUSTOMER table contains a BLOB column named PHOTO.

*

NAME='Kim Ralls'

另请参阅See Also

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值