Revert "PowerPC64 ELFv2 ABI: cases for in-register parameter passing, return values...
[mono.git] / mcs / class / System.ServiceModel / Test / System.ServiceModel.Dispatcher / Bug652331Test.cs
1 //
2 // Authors:
3 //      David Straw
4 //      Atsushi Enomoto <atsushi@ximian.com>
5 //
6 // Copyright (C) 2011 Novell, Inc.  http://www.novell.com
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining
9 // a copy of this software and associated documentation files (the
10 // "Software"), to deal in the Software without restriction, including
11 // without limitation the rights to use, copy, modify, merge, publish,
12 // distribute, sublicense, and/or sell copies of the Software, and to
13 // permit persons to whom the Software is furnished to do so, subject to
14 // the following conditions:
15 // 
16 // The above copyright notice and this permission notice shall be
17 // included in all copies or substantial portions of the Software.
18 // 
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 //
27 using System;
28 using System.Collections.Generic;
29 using System.Linq;
30 using System.Runtime.Serialization;
31 using System.ServiceModel;
32 using System.ServiceModel.Description;
33 using System.Threading;
34 using NUnit.Framework;
35
36 using WebServiceMoonlightTest.ServiceReference1;
37
38 namespace MonoTests.System.ServiceModel.Dispatcher
39 {
40         [TestFixture]
41         public class Bug652331Test
42         {
43                 [Test]
44                 public void Bug652331_2 () // test in one of the comment
45                 {
46                         // Init service
47                         ServiceHost serviceHost = new ServiceHost (typeof (Service1), new Uri ("http://localhost:37564/Service1"));
48                         serviceHost.AddServiceEndpoint (typeof (IService1), new BasicHttpBinding (), string.Empty);
49
50                         // Enable metadata exchange (WSDL publishing)
51                         var mexBehavior = new ServiceMetadataBehavior ();
52                         mexBehavior.HttpGetEnabled = true;
53                         serviceHost.Description.Behaviors.Add (mexBehavior);
54                         serviceHost.AddServiceEndpoint (typeof (IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding (), "mex");
55
56                         serviceHost.Open ();
57
58                         try {
59                                 // client
60                                 var binding = new BasicHttpBinding ();
61                                 var remoteAddress = new EndpointAddress ("http://localhost:37564/Service1");
62                                 var client = new Service1Client (binding, remoteAddress);
63
64                                 var wait = new ManualResetEvent (false);
65                                 client.GetDataCompleted += delegate (object o, GetDataCompletedEventArgs e) {
66                                         if (e.Error != null)
67                                                 throw e.Error;
68                                         Assert.AreEqual ("A", ((DataType1) e.Result).Id, "#1");
69                                         wait.Set ();
70                                 };
71
72                                 client.GetDataAsync ();
73                                 if (!wait.WaitOne (TimeSpan.FromSeconds (10)))
74                                         Assert.Fail ("timeout");
75                         } finally {
76                                 serviceHost.Close ();
77                         }
78                 }
79
80                 public class Service1 : IService1
81                 {
82                         public object GetData ()
83                         {
84                                 return new DataType1 { Id = "A" };
85                         }
86
87                         Func<object> d;
88                         public IAsyncResult BeginGetData (AsyncCallback callback, object state)
89                         {
90                                 if (d == null)
91                                 d = new Func<object> (GetData);
92                                 return d.BeginInvoke (callback, state);
93                         }
94
95                         public object EndGetData (IAsyncResult result)
96                         {
97                                 return d.EndInvoke (result);
98                         }
99                 }
100         }
101 }
102
103 // below are part of autogenerated code in comment #1 on bug #652331.
104
105 namespace WebServiceMoonlightTest.ServiceReference1 {
106
107     [System.Diagnostics.DebuggerStepThroughAttribute()]
108     [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
109     [System.Runtime.Serialization.DataContractAttribute(Name="DataType1", Namespace="http://mynamespace")]
110     public partial class DataType1 : object, System.ComponentModel.INotifyPropertyChanged {
111         
112         private string IdField;
113         
114         [System.Runtime.Serialization.DataMemberAttribute()]
115         public string Id {
116             get {
117                 return this.IdField;
118             }
119             set {
120                 if ((object.ReferenceEquals(this.IdField, value) != true)) {
121                     this.IdField = value;
122                     this.RaisePropertyChanged("Id");
123                 }
124             }
125         }
126         
127         public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
128         
129         protected void RaisePropertyChanged(string propertyName) {
130             System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
131             if ((propertyChanged != null)) {
132                 propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
133             }
134         }
135     }
136     
137     [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
138     [System.ServiceModel.ServiceContractAttribute(Namespace="http://mynamespace", ConfigurationName="ServiceReference1.IService1")]
139 [ServiceKnownType (typeof (DataType1))]
140     public interface IService1 {
141         
142         [System.ServiceModel.OperationContractAttribute(AsyncPattern=true, Action="http://mynamespace/IService1/GetData", ReplyAction="http://mynamespace/IService1/GetDataResponse")]
143         [System.ServiceModel.ServiceKnownTypeAttribute(typeof(WebServiceMoonlightTest.ServiceReference1.DataType1))]
144         System.IAsyncResult BeginGetData(System.AsyncCallback callback, object asyncState);
145         
146         object EndGetData(System.IAsyncResult result);
147     }
148     
149     [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
150     public interface IService1Channel : WebServiceMoonlightTest.ServiceReference1.IService1, System.ServiceModel.IClientChannel {
151     }
152     
153     [System.Diagnostics.DebuggerStepThroughAttribute()]
154     [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
155     public partial class GetDataCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
156         
157         private object[] results;
158         
159         public GetDataCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) : 
160                 base(exception, cancelled, userState) {
161             this.results = results;
162         }
163         
164         public object Result {
165             get {
166                 base.RaiseExceptionIfNecessary();
167                 return ((object)(this.results[0]));
168             }
169         }
170     }
171     
172     [System.Diagnostics.DebuggerStepThroughAttribute()]
173     [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
174     public partial class Service1Client : System.ServiceModel.ClientBase<WebServiceMoonlightTest.ServiceReference1.IService1>, WebServiceMoonlightTest.ServiceReference1.IService1 {
175         
176         private BeginOperationDelegate onBeginGetDataDelegate;
177         
178         private EndOperationDelegate onEndGetDataDelegate;
179         
180         private System.Threading.SendOrPostCallback onGetDataCompletedDelegate;
181         
182         private BeginOperationDelegate onBeginOpenDelegate;
183         
184         private EndOperationDelegate onEndOpenDelegate;
185         
186         private System.Threading.SendOrPostCallback onOpenCompletedDelegate;
187         
188         private BeginOperationDelegate onBeginCloseDelegate;
189         
190         private EndOperationDelegate onEndCloseDelegate;
191         
192         private System.Threading.SendOrPostCallback onCloseCompletedDelegate;
193         
194         public Service1Client() {
195         }
196         
197         public Service1Client(string endpointConfigurationName) : 
198                 base(endpointConfigurationName) {
199         }
200         
201         public Service1Client(string endpointConfigurationName, string remoteAddress) : 
202                 base(endpointConfigurationName, remoteAddress) {
203         }
204         
205         public Service1Client(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
206                 base(endpointConfigurationName, remoteAddress) {
207         }
208         
209         public Service1Client(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
210                 base(binding, remoteAddress) {
211         }
212         
213 /*
214         public System.Net.CookieContainer CookieContainer {
215             get {
216                 System.ServiceModel.Channels.IHttpCookieContainerManager httpCookieContainerManager = this.InnerChannel.GetProperty<System.ServiceModel.Channels.IHttpCookieContainerManager>();
217                 if ((httpCookieContainerManager != null)) {
218                     return httpCookieContainerManager.CookieContainer;
219                 }
220                 else {
221                     return null;
222                 }
223             }
224             set {
225                 System.ServiceModel.Channels.IHttpCookieContainerManager httpCookieContainerManager = this.InnerChannel.GetProperty<System.ServiceModel.Channels.IHttpCookieContainerManager>();
226                 if ((httpCookieContainerManager != null)) {
227                     httpCookieContainerManager.CookieContainer = value;
228                 }
229                 else {
230                     throw new System.InvalidOperationException("Unable to set the CookieContainer. Please make sure the binding contains an HttpC" +
231                             "ookieContainerBindingElement.");
232                 }
233             }
234         }
235 */
236         
237         public event System.EventHandler<GetDataCompletedEventArgs> GetDataCompleted;
238         
239         public event System.EventHandler<System.ComponentModel.AsyncCompletedEventArgs> OpenCompleted;
240         
241         public event System.EventHandler<System.ComponentModel.AsyncCompletedEventArgs> CloseCompleted;
242         
243         [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
244         System.IAsyncResult WebServiceMoonlightTest.ServiceReference1.IService1.BeginGetData(System.AsyncCallback callback, object asyncState) {
245             return base.Channel.BeginGetData(callback, asyncState);
246         }
247         
248         [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
249         object WebServiceMoonlightTest.ServiceReference1.IService1.EndGetData(System.IAsyncResult result) {
250             return base.Channel.EndGetData(result);
251         }
252         
253         private System.IAsyncResult OnBeginGetData(object[] inValues, System.AsyncCallback callback, object asyncState) {
254             return ((WebServiceMoonlightTest.ServiceReference1.IService1)(this)).BeginGetData(callback, asyncState);
255         }
256         
257         private object[] OnEndGetData(System.IAsyncResult result) {
258             object retVal = ((WebServiceMoonlightTest.ServiceReference1.IService1)(this)).EndGetData(result);
259             return new object[] {
260                     retVal};
261         }
262         
263         private void OnGetDataCompleted(object state) {
264             if ((this.GetDataCompleted != null)) {
265                 InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
266                 this.GetDataCompleted(this, new GetDataCompletedEventArgs(e.Results, e.Error, e.Cancelled, e.UserState));
267             }
268         }
269         
270         public void GetDataAsync() {
271             this.GetDataAsync(null);
272         }
273         
274         public void GetDataAsync(object userState) {
275             if ((this.onBeginGetDataDelegate == null)) {
276                 this.onBeginGetDataDelegate = new BeginOperationDelegate(this.OnBeginGetData);
277             }
278             if ((this.onEndGetDataDelegate == null)) {
279                 this.onEndGetDataDelegate = new EndOperationDelegate(this.OnEndGetData);
280             }
281             if ((this.onGetDataCompletedDelegate == null)) {
282                 this.onGetDataCompletedDelegate = new System.Threading.SendOrPostCallback(this.OnGetDataCompleted);
283             }
284             base.InvokeAsync(this.onBeginGetDataDelegate, null, this.onEndGetDataDelegate, this.onGetDataCompletedDelegate, userState);
285         }
286         
287         private System.IAsyncResult OnBeginOpen(object[] inValues, System.AsyncCallback callback, object asyncState) {
288             return ((System.ServiceModel.ICommunicationObject)(this)).BeginOpen(callback, asyncState);
289         }
290         
291         private object[] OnEndOpen(System.IAsyncResult result) {
292             ((System.ServiceModel.ICommunicationObject)(this)).EndOpen(result);
293             return null;
294         }
295         
296         private void OnOpenCompleted(object state) {
297             if ((this.OpenCompleted != null)) {
298                 InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
299                 this.OpenCompleted(this, new System.ComponentModel.AsyncCompletedEventArgs(e.Error, e.Cancelled, e.UserState));
300             }
301         }
302         
303         public void OpenAsync() {
304             this.OpenAsync(null);
305         }
306         
307         public void OpenAsync(object userState) {
308             if ((this.onBeginOpenDelegate == null)) {
309                 this.onBeginOpenDelegate = new BeginOperationDelegate(this.OnBeginOpen);
310             }
311             if ((this.onEndOpenDelegate == null)) {
312                 this.onEndOpenDelegate = new EndOperationDelegate(this.OnEndOpen);
313             }
314             if ((this.onOpenCompletedDelegate == null)) {
315                 this.onOpenCompletedDelegate = new System.Threading.SendOrPostCallback(this.OnOpenCompleted);
316             }
317             base.InvokeAsync(this.onBeginOpenDelegate, null, this.onEndOpenDelegate, this.onOpenCompletedDelegate, userState);
318         }
319         
320         private System.IAsyncResult OnBeginClose(object[] inValues, System.AsyncCallback callback, object asyncState) {
321             return ((System.ServiceModel.ICommunicationObject)(this)).BeginClose(callback, asyncState);
322         }
323         
324         private object[] OnEndClose(System.IAsyncResult result) {
325             ((System.ServiceModel.ICommunicationObject)(this)).EndClose(result);
326             return null;
327         }
328         
329         private void OnCloseCompleted(object state) {
330             if ((this.CloseCompleted != null)) {
331                 InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
332                 this.CloseCompleted(this, new System.ComponentModel.AsyncCompletedEventArgs(e.Error, e.Cancelled, e.UserState));
333             }
334         }
335         
336         public void CloseAsync() {
337             this.CloseAsync(null);
338         }
339         
340         public void CloseAsync(object userState) {
341             if ((this.onBeginCloseDelegate == null)) {
342                 this.onBeginCloseDelegate = new BeginOperationDelegate(this.OnBeginClose);
343             }
344             if ((this.onEndCloseDelegate == null)) {
345                 this.onEndCloseDelegate = new EndOperationDelegate(this.OnEndClose);
346             }
347             if ((this.onCloseCompletedDelegate == null)) {
348                 this.onCloseCompletedDelegate = new System.Threading.SendOrPostCallback(this.OnCloseCompleted);
349             }
350             base.InvokeAsync(this.onBeginCloseDelegate, null, this.onEndCloseDelegate, this.onCloseCompletedDelegate, userState);
351         }
352         
353 /*
354         protected override WebServiceMoonlightTest.ServiceReference1.IService1 CreateChannel() {
355             return new Service1ClientChannel(this);
356         }
357         
358         private class Service1ClientChannel : ChannelBase<WebServiceMoonlightTest.ServiceReference1.IService1>, WebServiceMoonlightTest.ServiceReference1.IService1 {
359             
360             public Service1ClientChannel(System.ServiceModel.ClientBase<WebServiceMoonlightTest.ServiceReference1.IService1> client) : 
361                     base(client) {
362             }
363             
364             public System.IAsyncResult BeginGetData(System.AsyncCallback callback, object asyncState) {
365                 object[] _args = new object[0];
366                 System.IAsyncResult _result = base.BeginInvoke("GetData", _args, callback, asyncState);
367                 return _result;
368             }
369             
370             public object EndGetData(System.IAsyncResult result) {
371                 object[] _args = new object[0];
372                 object _result = ((object)(base.EndInvoke("GetData", _args, result)));
373                 return _result;
374             }
375         }
376 */
377     }
378 }