本文整理汇总了C#中System.Runtime.Remoting.Messaging.ReturnMessage类的典型用法代码示例。如果您正苦于以下问题:C# ReturnMessage类的具体用法?C# ReturnMessage怎么用?C# ReturnMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ReturnMessage类属于System.Runtime.Remoting.Messaging命名空间,在下文中一共展示了ReturnMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Invoke
public override System.Runtime.Remoting.Messaging.IMessage Invoke(System.Runtime.Remoting.Messaging.IMessage msg)
{
IMethodCallMessage mcMsg = msg as IMethodCallMessage;
if (mcMsg != null)
{
ReturnMessage rlt = null;
if (!string.Equals(mcMsg.MethodName, "Test", StringComparison.OrdinalIgnoreCase))
{
object instance = null;
if (Entity == null)
{
Type type = Type.GetType(mcMsg.TypeName);
instance = Activator.CreateInstance(type);
}
else
{
instance = Entity;
}
object returnValueObject = mcMsg.MethodBase.Invoke(instance, null);
rlt = new ReturnMessage(returnValueObject, mcMsg.Args, mcMsg.ArgCount, mcMsg.LogicalCallContext, mcMsg);
}
else
{
rlt = new ReturnMessage(new ProxyResult(), mcMsg.Args, mcMsg.ArgCount, mcMsg.LogicalCallContext, mcMsg);
}
return rlt;
}
return null;
}
示例2: Invoke
public override System.Runtime.Remoting.Messaging.IMessage Invoke(System.Runtime.Remoting.Messaging.IMessage msg)
{
if (msg is IConstructionCallMessage) // 如果是构造函数,按原来的方式返回即可。
{
IConstructionCallMessage constructCallMsg = msg as IConstructionCallMessage;
IConstructionReturnMessage constructionReturnMessage = this.InitializeServerObject((IConstructionCallMessage)msg);
RealProxy.SetStubData(this, constructionReturnMessage.ReturnValue);
return constructionReturnMessage;
}
else if (msg is IMethodCallMessage) //如果是方法调用(属性也是方法调用的一种)
{
IMethodCallMessage callMsg = msg as IMethodCallMessage;
object[] args = callMsg.Args;
IMessage message;
try
{
if (callMsg.MethodName.StartsWith("set_") && args.Length == 1)
{
method.Invoke(GetUnwrappedServer(), new object[] { callMsg.MethodName.Substring(4)});
}
object o = callMsg.MethodBase.Invoke(GetUnwrappedServer(), args);
message = new ReturnMessage(o, args, args.Length, callMsg.LogicalCallContext, callMsg);
}
catch (Exception e)
{
message = new ReturnMessage(e, callMsg);
}
return message;
}
return msg;
}
示例3: SyncProcessMessage
public IMessage SyncProcessMessage(IMessage msg)
{
var mcm = (msg as IMethodCallMessage);
var mrm = null as IMethodReturnMessage;
var handler = ContextBoundObjectInterceptor.GetInterceptor(this.Target);
if (handler != null)
{
var arg = new InterceptionArgs(this.Target, mcm.MethodBase as MethodInfo, mcm.Args);
try
{
handler.Invoke(arg);
if (arg.Handled == true)
{
mrm = new ReturnMessage(arg.Result, new object[0], 0, mcm.LogicalCallContext, mcm);
}
}
catch (Exception ex)
{
mrm = new ReturnMessage(ex, mcm);
}
}
if (mrm == null)
{
mrm = this.NextSink.SyncProcessMessage(msg) as IMethodReturnMessage;
}
return mrm;
}
示例4: SyncProcessMessage
} // ObjectMode
public virtual IMessage SyncProcessMessage(IMessage msg)
{
IMessage replyMsg = null;
try
{
msg.Properties["__Uri"] = _realProxy.IdentityObject.URI;
if (_objectMode == WellKnownObjectMode.Singleton)
{
replyMsg = _realProxy.Invoke(msg);
}
else
{
// This is a single call object, so we need to create
// a new instance.
MarshalByRefObject obj = (MarshalByRefObject)Activator.CreateInstance(_serverType, true);
BCLDebug.Assert(RemotingServices.IsTransparentProxy(obj), "expecting a proxy");
RealProxy rp = RemotingServices.GetRealProxy(obj);
replyMsg = rp.Invoke(msg);
}
}
catch (Exception e)
{
replyMsg = new ReturnMessage(e, msg as IMethodCallMessage);
}
return replyMsg;
} // SyncProcessMessage
示例5: SyncProcessMessage
public IMessage SyncProcessMessage (IMessage msg)
{
ServerIdentity identity = (ServerIdentity) RemotingServices.GetMessageTargetIdentity (msg);
Context oldContext = null;
IMessage response;
if (Threading.Thread.CurrentContext != identity.Context)
oldContext = Context.SwitchToContext (identity.Context);
try
{
Context.NotifyGlobalDynamicSinks (true, msg, false, false);
Thread.CurrentContext.NotifyDynamicSinks (true, msg, false, false);
response = identity.Context.GetServerContextSinkChain().SyncProcessMessage (msg);
Context.NotifyGlobalDynamicSinks (false, msg, false, false);
Thread.CurrentContext.NotifyDynamicSinks (false, msg, false, false);
}
catch (Exception ex)
{
response = new ReturnMessage (ex, (IMethodCallMessage)msg);
}
finally
{
if (oldContext != null)
Context.SwitchToContext (oldContext);
}
return response;
}
示例6: Invoke
/// <summary>
/// 函数消息
/// </summary>
/// <param name="msg"></param>
/// <returns></returns>
public override IMessage Invoke(IMessage msg)
{
IMessage message;
var callMessage = msg as IConstructionCallMessage;
if (callMessage != null)
{
message = InitializeServerObject(callMessage);
if (message != null)
{
SetStubData(this, ((IConstructionReturnMessage)message).ReturnValue);
}
}
else
{
var callMsg = (IMethodCallMessage)msg;
var attributes = serverType.GetMethod(callMsg.MethodName).GetCustomAttributes(false);
var args = callMsg.Args;
try
{
OnBegin(attributes, callMsg);
var ret = callMsg.MethodBase.Invoke(GetUnwrappedServer(), args);
OnComplete(attributes, ref ret, callMsg);
message = new ReturnMessage(ret, args, args.Length, callMsg.LogicalCallContext, callMsg);
}
catch (Exception e)
{
OnException(attributes, e.InnerException, callMsg);
message = new ReturnMessage(e.InnerException, callMsg);
}
}
return message;
}
示例7: DeserializeMessage
private IMessage DeserializeMessage(IMethodCallMessage mcm, ITransportHeaders headers, Stream stream)
{
IMessage message;
string str2;
string str3;
Header[] h = new Header[] { new Header("__TypeName", mcm.TypeName), new Header("__MethodName", mcm.MethodName), new Header("__MethodSignature", mcm.MethodSignature) };
string contentType = headers["Content-Type"] as string;
HttpChannelHelper.ParseContentType(contentType, out str2, out str3);
if (string.Compare(str2, "text/xml", StringComparison.Ordinal) == 0)
{
message = CoreChannel.DeserializeSoapResponseMessage(stream, mcm, h, this._strictBinding);
}
else
{
int count = 0x400;
byte[] buffer = new byte[count];
StringBuilder builder = new StringBuilder();
for (int i = stream.Read(buffer, 0, count); i > 0; i = stream.Read(buffer, 0, count))
{
builder.Append(Encoding.ASCII.GetString(buffer, 0, i));
}
message = new ReturnMessage(new RemotingException(builder.ToString()), mcm);
}
stream.Close();
return message;
}
示例8: Invoke
public override IMessage Invoke(IMessage msg)
{
using (var client = WcfServiceClientFactory.CreateServiceClient<IWcfLogService>())
{
var channel = client.Channel;
IMethodCallMessage methodCall = (IMethodCallMessage)msg;
IMethodReturnMessage methodReturn = null;
object[] copiedArgs = Array.CreateInstance(typeof(object), methodCall.Args.Length) as object[];
methodCall.Args.CopyTo(copiedArgs, 0);
try
{
object returnValue = methodCall.MethodBase.Invoke(channel, copiedArgs);
methodReturn = new ReturnMessage(returnValue,
copiedArgs,
copiedArgs.Length,
methodCall.LogicalCallContext,
methodCall);
}
catch (Exception ex)
{
if (ex.InnerException != null)
{
LocalLogService.Log(ex.InnerException.ToString());
methodReturn = new ReturnMessage(ex.InnerException, methodCall);
}
else
{
LocalLogService.Log(ex.ToString());
methodReturn = new ReturnMessage(ex, methodCall);
}
}
return methodReturn;
}
}
示例9: Invoke
/// <summary>
/// Proxy method for substitution of executing methods in adapter interface.
/// </summary>
/// <param name="methodCall">The IMessage containing method invoking data.</param>
/// <returns>The IMessage containing method return data.</returns>
protected override IMessage Invoke(IMethodCallMessage methodCall)
{
ReturnMessage mret = null;
// Check if this is a method from IAdapter. Any IAdapter methods should be ignored.
if ((methodCall.MethodBase.DeclaringType.FullName != typeof(IAdapter).FullName)
&& (methodCall.MethodBase.DeclaringType.FullName != typeof(IDisposable).FullName)
)
{
TestSite.Log.Add(LogEntryKind.EnterAdapter,
"Interactive adapter: {0}, method: {1}",
ProxyType.Name,
methodCall.MethodName);
try
{
// Instantiate a new UI window.
using (InteractiveAdapterDialog adapterDlg = new InteractiveAdapterDialog(methodCall, TestSite.Properties))
{
DialogResult dialogResult = adapterDlg.ShowDialog();
if (dialogResult != DialogResult.OK)
{
string msg = "Failed";
TestSite.Assume.Fail(msg);
}
else
{
mret = new ReturnMessage(
adapterDlg.ReturnValue,
adapterDlg.OutArgs.Length > 0 ? adapterDlg.OutArgs : null,
adapterDlg.OutArgs.Length,
methodCall.LogicalCallContext,
methodCall);
}
}
}
catch (Exception ex)
{
TestSite.Log.Add(LogEntryKind.Debug, ex.ToString());
throw;
}
finally
{
TestSite.Log.Add(LogEntryKind.ExitAdapter,
"Interactive adapter: {0}, method: {1}",
ProxyType.Name,
methodCall.MethodName);
}
}
else
{
// TODO: Do we need to take care ReturnMessage (Exception, IMethodCallMessage) ?
mret = new ReturnMessage(null, null, 0, methodCall.LogicalCallContext, methodCall);
}
return mret;
}
示例10: ValidateMessage
/*
* Checks the replySink param for NULL and type.
* If the param is good, it returns NULL.
* Else it returns a Message with the relevant exception.
*/
internal static IMessage ValidateMessage(IMessage reqMsg)
{
IMessage retMsg = null;
if (reqMsg == null)
{
retMsg = new ReturnMessage( new ArgumentNullException("reqMsg"), null);
}
return retMsg;
}
示例11: Invoke
public override IMessage Invoke(IMessage message)
{
IMessage result = null;
IMethodCallMessage methodCall = message as IMethodCallMessage;
MethodInfo method = methodCall.MethodBase as MethodInfo;
// Invoke
if (result == null) {
if (proxyTarget != null) {
Console.WriteLine("proxy going to invoke: {0}", method.Name);
object callResult;
object actualresult;
bool make_proxy = true;
if (method.ReturnType.IsInterface) {
actualresult = method.Invoke(proxyTarget, methodCall.InArgs);
if (method.ReturnType.IsGenericType) {
// Console.WriteLine("** return value is generic type: {0}", method.ReturnType.GetGenericTypeDefinition());
if (method.ReturnType.GetGenericTypeDefinition() == (typeof(IEnumerator<>))) {
Console.WriteLine("** method returning IEnumerator<>, making BatchProxy");
Type[] args = method.ReturnType.GetGenericArguments();
Type srvbatchtype = typeof(EnumeratorServerBatch<>).MakeGenericType(args);
object srv = Activator.CreateInstance(srvbatchtype, actualresult);
Type clbatchtype = typeof(EnumeratorClientBatch<>).MakeGenericType(args);
object client = Activator.CreateInstance(clbatchtype, srv);
make_proxy = false;
actualresult = client;
}
}
if (make_proxy) {
var newproxy = new MyProxy(method.ReturnType, actualresult);
callResult = newproxy.GetTransparentProxy();
} else {
callResult = actualresult;
}
} else {
callResult = method.Invoke(proxyTarget, methodCall.InArgs);
}
Console.WriteLine("proxy done Invoking: {0}", method.Name);
LogicalCallContext context = methodCall.LogicalCallContext;
result = new ReturnMessage(callResult, null, 0, context, message as IMethodCallMessage);
} else {
NotSupportedException exception = new NotSupportedException("proxyTarget is not defined");
result = new ReturnMessage(exception, message as IMethodCallMessage);
}
}
return result;
}
示例12: SetNewReturnValue
public void SetNewReturnValue(object newReturnValue)
{
IMethodReturnMessage message = this.methodCallReturnMessage;
if(message==null)
{
return ;
}
ReturnMessage newReturnMessage = new ReturnMessage(newReturnValue,message.OutArgs,message.OutArgCount,message.LogicalCallContext,this.MethodCallMessage);
this.MethodCallReturnMessage = newReturnMessage;
}
示例13: Process
public void Process(IMethodCallMessage callMsg, ref IMethodReturnMessage retMsg)
{
Exception e = retMsg.Exception;
if (e != null)
{
this.HandleException(e);
Exception newException = this.GetNewException(e);
if (!object.ReferenceEquals(e, newException))
retMsg = new ReturnMessage(newException, callMsg);
}
}
示例14: FlagCurrentMethodToBeSkipped
protected void FlagCurrentMethodToBeSkipped(ProcessEventArgs args)
{
IMethodCallMessage methodCallMessage = args.MethodCallMessage;
ReturnMessage customMessage = new ReturnMessage(
1,
new object[]{},
0,
methodCallMessage.LogicalCallContext,
methodCallMessage);
methodCallMessage.LogicalCallContext.SetData("CustomReturnMessage",customMessage) ;
}
示例15: Postprocess
public void Postprocess(MarshalByRefObject inst, IMessage msg, ref IMessage msgReturn)
{
IMethodCallMessage lMsgIn = msg as IMethodCallMessage;
IMethodReturnMessage lMsgOut = msgReturn as IMethodReturnMessage;
// Extract Server
ONServer lServer = inst as ONServer;
// Calculate OutputArgumets
object[] lArgs = lMsgOut.Args;
mServiceCacheItem.InvoqueOutboundArguments(lServer, lArgs);
// Pop the OID from Class Stack
lServer.OnContext.OperationStack.Pop();
mInStack = false;
msgReturn = new ReturnMessage(lMsgOut.ReturnValue, lArgs, lArgs.Length, lMsgOut.LogicalCallContext, lMsgIn);
}