Ref parameter was not covered by ParameterInfo.IsOut. Fixed bug #696784.
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel / ServiceProxyGenerator.cs
1 #if DISABLE_REAL_PROXY
2 //
3 // ServiceProxyGenerator.cs
4 //
5 // Author:
6 //      Atsushi Enomoto <atsushi@ximian.com>
7 //
8 // Copyright (C) 2009 Novell, Inc.  http://www.novell.com
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29 using System;
30 using System.Collections.Generic;
31 using System.Linq;
32 using System.Reflection;
33 using System.ServiceModel.Channels;
34 using System.ServiceModel.Description;
35 using System.ServiceModel.Dispatcher;
36 using Mono.CodeGeneration;
37 using System.ServiceModel.MonoInternal;
38
39 namespace System.ServiceModel
40 {
41         internal class ServiceProxyGenerator : ProxyGeneratorBase
42         {
43                 public static Type CreateCallbackProxyType (DispatchRuntime dispatchRuntime, Type callbackType)
44                 {
45                         var ed = dispatchRuntime.EndpointDispatcher;
46                         var channelDispatcher = ed.ChannelDispatcher;
47                         Type contractType = channelDispatcher != null ? channelDispatcher.Host.ImplementedContracts.Values.First (hcd => hcd.Name == ed.ContractName && hcd.Namespace == ed.ContractNamespace).ContractType : dispatchRuntime.Type;
48
49                         var cd = ContractDescriptionGenerator.GetCallbackContract (contractType, callbackType);
50                         string modname = "dummy";
51                         Type crtype = typeof (DuplexServiceRuntimeChannel);
52
53                         // public class __clientproxy_MyContract : ClientRuntimeChannel, [ContractType]
54                         CodeClass c = new CodeModule (modname).CreateClass (
55                                 "__callbackproxy_" + cd.Name,
56                                 crtype,
57                                 new Type [] {callbackType});
58
59                         //
60                         // public __callbackproxy_MyContract (
61                         //      IChannel channel, DispatchRuntime runtime)
62                         //      : base (channel, runtime)
63                         // {
64                         // }
65                         //
66                         Type [] ctorargs = new Type [] {typeof (IChannel), typeof (DispatchRuntime)};
67                         CodeMethod ctor = c.CreateConstructor (
68                                 MethodAttributes.Public, ctorargs);
69                         CodeBuilder b = ctor.CodeBuilder;
70                         MethodBase baseCtor = crtype.GetConstructors (
71                                 BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) [0];
72                         if (baseCtor == null) throw new Exception ("INTERNAL ERROR: DuplexServiceRuntimeChannel.ctor() was not found.");
73                         b.Call (
74                                 ctor.GetThis (),
75                                 baseCtor,
76                                 new CodeArgumentReference (typeof (IChannel), 1, "arg0"),
77                                 new CodeArgumentReference (typeof (DispatchRuntime), 2, "arg1"));
78
79                         return CreateProxyTypeOperations (crtype, c, cd);
80                 }
81         }
82 }
83 #endif