本文整理汇总了C#中IServiceRequest.Encode方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceRequest.Encode方法的具体用法?C# IServiceRequest.Encode怎么用?C# IServiceRequest.Encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceRequest
的用法示例。
在下文中一共展示了IServiceRequest.Encode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendServiceRequestAsync
private async Task SendServiceRequestAsync(IServiceRequest request, CancellationToken token)
{
var bodyStream = SerializableBytes.CreateWritableStream();
var bodyEncoder = new BinaryEncoder(bodyStream, this);
try
{
ExpandedNodeId binaryEncodingId;
if (!TypeToBinaryEncodingIdDictionary.TryGetValue(request.GetType(), out binaryEncodingId))
{
throw new ServiceResultException(StatusCodes.BadDataTypeIdUnknown);
}
bodyEncoder.WriteNodeId(null, ExpandedNodeId.ToNodeId(binaryEncodingId, this.NamespaceUris));
request.Encode(bodyEncoder);
bodyStream.Position = 0;
if (bodyStream.Length > this.RemoteMaxMessageSize)
{
throw new ServiceResultException(StatusCodes.BadEncodingLimitsExceeded);
}
// write chunks
int chunkCount = 0;
int bodyCount = (int)(bodyStream.Length - bodyStream.Position);
while (bodyCount > 0)
{
chunkCount++;
if (this.RemoteMaxChunkCount > 0 && chunkCount > this.RemoteMaxChunkCount)
{
throw new ServiceResultException(StatusCodes.BadEncodingLimitsExceeded);
}
var stream = new MemoryStream(this.sendBuffer, 0, (int)this.RemoteReceiveBufferSize, true, true);
var encoder = new BinaryEncoder(stream, this);
try
{
// header
encoder.WriteUInt32(null, UaTcpMessageTypes.MSGF);
encoder.WriteUInt32(null, 0u);
encoder.WriteUInt32(null, this.ChannelId);
// symmetric security header
encoder.WriteUInt32(null, this.TokenId);
// detect new TokenId
if (this.TokenId != this.currentClientTokenId)
{
this.currentClientTokenId = this.TokenId;
// update signer and encrypter with new symmetric keys
if (this.symIsSigned)
{
this.symSigner.Key = this.clientSigningKey;
if (this.symIsEncrypted)
{
this.currentClientEncryptingKey = this.clientEncryptingKey;
this.currentClientInitializationVector = this.clientInitializationVector;
this.symEncryptor = this.symEncryptionAlgorithm.CreateEncryptor(this.currentClientEncryptingKey, this.currentClientInitializationVector);
}
}
}
int plainHeaderSize = encoder.Position;
// sequence header
encoder.WriteUInt32(null, this.GetNextSequenceNumber());
encoder.WriteUInt32(null, request.RequestHeader.RequestHandle);
// body
int paddingHeaderSize;
int maxBodySize;
int bodySize;
int paddingSize;
int chunkSize;
if (this.symIsEncrypted)
{
paddingHeaderSize = this.symEncryptionBlockSize > 256 ? 2 : 1;
maxBodySize = ((((int)this.RemoteReceiveBufferSize - plainHeaderSize - this.symSignatureSize - paddingHeaderSize) / this.symEncryptionBlockSize) * this.symEncryptionBlockSize) - SequenceHeaderSize;
if (bodyCount < maxBodySize)
{
bodySize = bodyCount;
paddingSize = (this.symEncryptionBlockSize - ((SequenceHeaderSize + bodySize + paddingHeaderSize + this.symSignatureSize) % this.symEncryptionBlockSize)) % this.symEncryptionBlockSize;
}
else
{
bodySize = maxBodySize;
paddingSize = 0;
}
chunkSize = plainHeaderSize + (((SequenceHeaderSize + bodySize + paddingSize + paddingHeaderSize + this.symSignatureSize) / this.symEncryptionBlockSize) * this.symEncryptionBlockSize);
}
else
{
paddingHeaderSize = 0;
paddingSize = 0;
maxBodySize = (int)this.RemoteReceiveBufferSize - plainHeaderSize - this.symSignatureSize - SequenceHeaderSize;
if (bodyCount < maxBodySize)
{
bodySize = bodyCount;
}
else
//.........这里部分代码省略.........