本文整理汇总了C#中ITransportHeaders类的典型用法代码示例。如果您正苦于以下问题:C# ITransportHeaders类的具体用法?C# ITransportHeaders怎么用?C# ITransportHeaders使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ITransportHeaders类属于命名空间,在下文中一共展示了ITransportHeaders类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReceiveRequest
public void ReceiveRequest(out ITransportHeaders requestHeaders, out Stream requestStream)
{
// transport signature
if (!MatchPreamble())
BinaryWireProtocol.ThrowException(BinaryWireProtocol.StatusCode.InvalidMessageFormat);
// operation opcode
byte operation = _reader.ReadByte();
if (operation != BinaryWireProtocol.OperationType.Request && operation != BinaryWireProtocol.OperationType.OneWayRequest)
BinaryWireProtocol.ThrowException(BinaryWireProtocol.StatusCode.InvalidMessageFormat);
// content length
int contentLength = _reader.ReadInt32();
// request uri
string requestUri = _reader.ReadString();
if (!CheckRequestUri(requestUri))
BinaryWireProtocol.ThrowException(BinaryWireProtocol.StatusCode.InvalidRequestUri);
// request headers
requestHeaders = ReadHeaders();
// set special headers
requestHeaders[BinaryWireProtocol.WellKnownHeaders.ConnectionId] = _connectionId;
requestHeaders[BinaryWireProtocol.WellKnownHeaders.RequestUri] = requestUri;
// create stream for request reading
if (contentLength == -1)
{
requestStream = new ChunkedReadStream(_bufferedStream);
}
else
{
requestStream = new FixedReadStream(_bufferedStream, contentLength);
}
// set client principal
RemotingService.ClientPrincipal = _transport.ClientPrincipal;
}
示例2: GetResponseStream
public Stream GetResponseStream (IServerResponseChannelSinkStack sinkStack,
object state,
IMessage msg,
ITransportHeaders headers)
{
throw new NotImplementedException();
}
示例3: GetResponseStream
public Stream GetResponseStream (IServerResponseChannelSinkStack sinkStack,
object state,
IMessage msg,
ITransportHeaders headers)
{
return null;
}
示例4: AsyncProcessRequest
public void AsyncProcessRequest(
IClientChannelSinkStack sinkStack_in,
IMessage msg_in,
ITransportHeaders headers_in,
Stream stream_in
) {
#region encrypt...
headers_in[EncryptionHelper.X_ENCRYPT] = "1";
headers_in[EncryptionHelper.X_CLIENTID] = this.clientid_;
stream_in
= EncryptionHelper.Encrypt(
stream_in,
false,
this.keyspath_,
this.clientid_
);
#endregion
sinkStack_in.Push(this, null);
this.nextchannelsink_.AsyncProcessRequest(
sinkStack_in,
msg_in,
headers_in,
stream_in
);
}
示例5: AsyncProcessRequest
public void AsyncProcessRequest(IClientChannelSinkStack sinkStack, IMessage msg, ITransportHeaders headers, Stream requestStream)
{
ITransportHeaders headers2;
Stream stream;
AsyncCallback callback = new AsyncCallback(this.AsyncFinishedCallback);
new AsyncMessageDelegate(this.AsyncProcessMessage).BeginInvoke(msg, headers, requestStream, out headers2, out stream, sinkStack, callback, null);
}
示例6: isHeaderCompressed_
private static bool isHeaderCompressed_(ITransportHeaders headers_in) {
return (
(headers_in[CompressionHelper.X_COMPRESS] != null)
&&
((string)headers_in[CompressionHelper.X_COMPRESS] == "1")
);
}
示例7: AsyncProcessResponse
public void AsyncProcessResponse(IClientResponseChannelSinkStack sinkStack, object state, ITransportHeaders responseHeaders, Stream responseStream)
{
// parameters validation
if (sinkStack == null)
throw new ArgumentNullException("sinkStack");
if (responseHeaders == null)
throw new ArgumentNullException("responseHeaders");
if (responseStream == null)
throw new ArgumentNullException("responseStream");
IMethodCallMessage methodCall = state as IMethodCallMessage;
if (methodCall == null)
throw new NotSupportedException();
IMethodReturnMessage methodReturn;
try
{
// deserialize response
methodReturn = _formatter.DeserializeResponse(methodCall, responseHeaders, responseStream);
responseStream.Close();
}
catch (Exception ex)
{
methodReturn = new ReturnMessage(ex, methodCall);
}
// dispatch response
sinkStack.DispatchReplyMessage(methodReturn);
}
示例8: Read
public IPEndPoint Read(out ITransportHeaders headers, out Stream stream, out IPEndPoint remote)
{
// FIXME: 1) reliability 2) exceptions
remote = new IPEndPoint(IPAddress.Loopback, 0);
var buffer = UdpClient.Receive(ref remote);
using (var ms = new MemoryStream(buffer))
using (var br = new BinaryReader(ms))
{
var marker = br.ReadInt16();
if (marker != HeaderMarker && marker != DataMarker)
{
throw new InvalidDataException("Unexpected datagram format");
}
// read transport headers
headers = new TransportHeaders();
while (marker != DataMarker)
{
var name = br.ReadString();
var value = br.ReadString();
headers[name] = value;
marker = br.ReadInt16();
}
// get response stream
var length = br.ReadInt32();
stream = new MemoryStream(buffer, (int)ms.Position, length);
}
return remote;
}
示例9: Write
public void Write(ITransportHeaders headers, Stream stream, IPEndPoint endpoint)
{
using (var ms = new MemoryStream())
using (var bw = new BinaryWriter(ms))
{
foreach (DictionaryEntry entry in headers)
{
bw.Write(HeaderMarker);
bw.Write(entry.Key.ToString());
bw.Write(entry.Value.ToString());
}
var length = (int)stream.Length;
var br = new BinaryReader(stream);
bw.Write(DataMarker);
bw.Write(length);
bw.Write(br.ReadBytes(length));
bw.Flush();
// FIXME: 1) reliability 2) check buffer size
var buffer = ms.ToArray();
UdpClient.Send(buffer, buffer.Length, endpoint);
}
}
示例10: ProcessMessage
public ServerProcessing ProcessMessage(
IServerChannelSinkStack sinkStack_in,
IMessage requestMsg_in,
ITransportHeaders requestHeaders_in,
Stream requestStream_in,
out IMessage responseMsg_out,
out ITransportHeaders responseHeaders_out,
out Stream responseStream_out
) {
if (nextchannelsink_ != null) {
CallContext.SetData(
"ClientIPAddress",
((IPAddress)requestHeaders_in[CommonTransportKeys.IPAddress]).ToString()
);
ServerProcessing _serverprocessing = NextChannelSink.ProcessMessage(
sinkStack_in,
requestMsg_in,
requestHeaders_in,
requestStream_in,
out responseMsg_out,
out responseHeaders_out,
out responseStream_out
);
return _serverprocessing;
} else {
responseMsg_out = null;
responseHeaders_out = null;
responseStream_out = null;
return new ServerProcessing();
}
}
示例11: GetChannelHeaders
private Header[] GetChannelHeaders(ITransportHeaders requestHeaders, out string soapActionToVerify)
{
string str3;
string str4;
soapActionToVerify = null;
string uRI = (string) requestHeaders["__RequestUri"];
string uri = (string) requestHeaders["SOAPAction"];
if (uri == null)
{
throw new RemotingException(CoreChannel.GetResourceString("Remoting_SoapActionMissing"));
}
uri = HttpEncodingHelper.DecodeUri(uri);
soapActionToVerify = uri;
if (!SoapServices.GetTypeAndMethodNameFromSoapAction(uri, out str3, out str4))
{
Type serverTypeForUri = RemotingServices.GetServerTypeForUri(uRI);
if (serverTypeForUri == null)
{
throw new RemotingException(string.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_TypeNotFoundFromUri"), new object[] { uRI }));
}
str3 = "clr:" + serverTypeForUri.FullName + ", " + serverTypeForUri.Assembly.GetName().Name;
}
else
{
str3 = "clr:" + str3;
}
int num = 2;
Header[] headerArray = new Header[num];
headerArray[0] = new Header("__Uri", uRI);
headerArray[1] = new Header("__TypeName", str3);
return headerArray;
}
示例12: ProcessRequest
protected override void ProcessRequest(IMessage message, ITransportHeaders headers, ref Stream stream, ref object state)
{
if (headers["CustomEncryption"] != null && headers["Credentials"] != null)
{
var args = new EncryptCredentials(headers["Credentials"].ToString());
User user = new User();
user.Username = string.Format("{0}", args["Username"]);
user.Password = string.Format("{0}", args["Password"]);
user.AddressTable.Add(user.Username, string.Format("{0}", args["Uri"]));
UserDataManager userManager = new UserDataManager();
if (user != null && userManager.UserLogOn(user.Username, user.Password) != null)
{
// okay
Console.WriteLine(
"AuthServerSink: retrieved valid credential information: username: {0}, password {1}.",
user.Username, user.Password);
LoginInfo.Authenticated = true;
LoginInfo.LoginName = user.Username;
LoginInfo.LoginPassword = user.Password;
Console.WriteLine("EncryptServerSink: decrypting request");
stream = this.Decrypt(stream);
state = true;
return;
}
}
// not good!
Console.WriteLine(
"DemoCredentialsServerSink: retrieved bad credentials or credentials are missing. Throwing an exception.");
throw new RemotingException("Invalid credentials.");
}
示例13: AsyncProcessRequest
public void AsyncProcessRequest(IClientChannelSinkStack sinkStack, IMessage msg, ITransportHeaders requestHeaders, Stream requestStream)
{
// add message Uri to headers
var mcm = (IMethodCallMessage)msg;
requestHeaders[CommonTransportKeys.RequestUri] = mcm.Uri;
// send data (FIXME: 1) add reliability, 2) handle exceptions)
var transport = new UdpTransport(UdpClient);
transport.Write(requestHeaders, requestStream, ServerEndpoint);
// if the call is not one-way, schedule an async call
if (!RemotingServices.IsOneWay(mcm.MethodBase))
{
ThreadPool.QueueUserWorkItem((s) =>
{
try
{
ITransportHeaders responseHeaders;
Stream responseStream;
IPEndPoint remote;
transport.Read(out responseHeaders, out responseStream, out remote);
sinkStack.AsyncProcessResponse(responseHeaders, responseStream);
}
catch (Exception ex)
{
sinkStack.DispatchException(ex);
}
});
}
}
示例14: AsyncProcessRequest
/// <summary>
/// Processes an asynchronous request.
/// </summary>
/// <param name="sinkStack">Channel sink stack</param>
/// <param name="msg">Message to processed</param>
/// <param name="headers">Transport headers</param>
/// <param name="stream">Request stream</param>
public void AsyncProcessRequest(IClientChannelSinkStack sinkStack, IMessage msg, ITransportHeaders headers, Stream stream)
{
stream = CreateEnvelope(stream, headers);
sinkStack.Push(this, null);
_nextSink.AsyncProcessRequest(sinkStack, msg, headers, stream);
}
示例15: ProcessMessage
public ServerProcessing ProcessMessage (IServerChannelSinkStack sinkStack,
IMessage requestMsg,
ITransportHeaders requestHeaders,
Stream requestStream,
out IMessage responseMsg,
out ITransportHeaders responseHeaders,
out Stream responseStream)
{
IMessage call;
string uri = (string)requestHeaders [CommonTransportKeys.RequestUri];
if (requestMsg == null) {
call = (IMessage)format.DeserializeRequest (requestStream, uri);
} else {
call = requestMsg;
}
next_sink.ProcessMessage (sinkStack, call, requestHeaders, null,
out responseMsg, out responseHeaders, out responseStream);
responseStream = new MemoryStream ();
format.SerializeResponse (responseStream, responseMsg);
return ServerProcessing.Complete;
}