| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381 |
- //
- // Authors:
- // David Straw
- // Atsushi Enomoto <[email protected]>
- //
- // Copyright (C) 2011 Novell, Inc. http://www.novell.com
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.Serialization;
- using System.ServiceModel;
- using System.ServiceModel.Description;
- using System.Threading;
- using NUnit.Framework;
- using WebServiceMoonlightTest.ServiceReference1;
- using MonoTests.Helpers;
- namespace MonoTests.System.ServiceModel.Dispatcher
- {
- [TestFixture]
- public class Bug652331Test
- {
- [Test]
- public void Bug652331_2 () // test in one of the comment
- {
- // Init service
- int port = NetworkHelpers.FindFreePort ();
- ServiceHost serviceHost = new ServiceHost (typeof (Service1), new Uri ("http://localhost:" + port + "/Service1"));
- serviceHost.AddServiceEndpoint (typeof (IService1), new BasicHttpBinding (), string.Empty);
- // Enable metadata exchange (WSDL publishing)
- var mexBehavior = new ServiceMetadataBehavior ();
- mexBehavior.HttpGetEnabled = true;
- serviceHost.Description.Behaviors.Add (mexBehavior);
- serviceHost.AddServiceEndpoint (typeof (IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding (), "mex");
- serviceHost.Open ();
- try {
- // client
- var binding = new BasicHttpBinding ();
- var remoteAddress = new EndpointAddress ("http://localhost:" + port + "/Service1");
- var client = new Service1Client (binding, remoteAddress);
- var wait = new ManualResetEvent (false);
- client.GetDataCompleted += delegate (object o, GetDataCompletedEventArgs e) {
- if (e.Error != null)
- throw e.Error;
- Assert.AreEqual ("A", ((DataType1) e.Result).Id, "#1");
- wait.Set ();
- };
- client.GetDataAsync ();
- if (!wait.WaitOne (TimeSpan.FromSeconds (20)))
- Assert.Fail ("timeout");
- } finally {
- serviceHost.Close ();
- }
- }
- public class Service1 : IService1
- {
- public object GetData ()
- {
- return new DataType1 { Id = "A" };
- }
- Func<object> d;
- public IAsyncResult BeginGetData (AsyncCallback callback, object state)
- {
- if (d == null)
- d = new Func<object> (GetData);
- return d.BeginInvoke (callback, state);
- }
- public object EndGetData (IAsyncResult result)
- {
- return d.EndInvoke (result);
- }
- }
- }
- }
- // below are part of autogenerated code in comment #1 on bug #652331.
- namespace WebServiceMoonlightTest.ServiceReference1 {
- [System.Diagnostics.DebuggerStepThroughAttribute()]
- [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
- [System.Runtime.Serialization.DataContractAttribute(Name="DataType1", Namespace="http://mynamespace")]
- public partial class DataType1 : object, System.ComponentModel.INotifyPropertyChanged {
-
- private string IdField;
-
- [System.Runtime.Serialization.DataMemberAttribute()]
- public string Id {
- get {
- return this.IdField;
- }
- set {
- if ((object.ReferenceEquals(this.IdField, value) != true)) {
- this.IdField = value;
- this.RaisePropertyChanged("Id");
- }
- }
- }
-
- public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
-
- protected void RaisePropertyChanged(string propertyName) {
- System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
- if ((propertyChanged != null)) {
- propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
- }
- }
- }
-
- [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
- [System.ServiceModel.ServiceContractAttribute(Namespace="http://mynamespace", ConfigurationName="ServiceReference1.IService1")]
- [ServiceKnownType (typeof (DataType1))]
- public interface IService1 {
-
- [System.ServiceModel.OperationContractAttribute(AsyncPattern=true, Action="http://mynamespace/IService1/GetData", ReplyAction="http://mynamespace/IService1/GetDataResponse")]
- [System.ServiceModel.ServiceKnownTypeAttribute(typeof(WebServiceMoonlightTest.ServiceReference1.DataType1))]
- System.IAsyncResult BeginGetData(System.AsyncCallback callback, object asyncState);
-
- object EndGetData(System.IAsyncResult result);
- }
-
- [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
- public interface IService1Channel : WebServiceMoonlightTest.ServiceReference1.IService1, System.ServiceModel.IClientChannel {
- }
-
- [System.Diagnostics.DebuggerStepThroughAttribute()]
- [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
- public partial class GetDataCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
-
- private object[] results;
-
- public GetDataCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
- base(exception, cancelled, userState) {
- this.results = results;
- }
-
- public object Result {
- get {
- base.RaiseExceptionIfNecessary();
- return ((object)(this.results[0]));
- }
- }
- }
-
- [System.Diagnostics.DebuggerStepThroughAttribute()]
- [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
- public partial class Service1Client : System.ServiceModel.ClientBase<WebServiceMoonlightTest.ServiceReference1.IService1>, WebServiceMoonlightTest.ServiceReference1.IService1 {
-
- private BeginOperationDelegate onBeginGetDataDelegate;
-
- private EndOperationDelegate onEndGetDataDelegate;
-
- private System.Threading.SendOrPostCallback onGetDataCompletedDelegate;
-
- private BeginOperationDelegate onBeginOpenDelegate;
-
- private EndOperationDelegate onEndOpenDelegate;
-
- private System.Threading.SendOrPostCallback onOpenCompletedDelegate;
-
- private BeginOperationDelegate onBeginCloseDelegate;
-
- private EndOperationDelegate onEndCloseDelegate;
-
- private System.Threading.SendOrPostCallback onCloseCompletedDelegate;
-
- public Service1Client() {
- }
-
- public Service1Client(string endpointConfigurationName) :
- base(endpointConfigurationName) {
- }
-
- public Service1Client(string endpointConfigurationName, string remoteAddress) :
- base(endpointConfigurationName, remoteAddress) {
- }
-
- public Service1Client(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
- base(endpointConfigurationName, remoteAddress) {
- }
-
- public Service1Client(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
- base(binding, remoteAddress) {
- }
-
- /*
- public System.Net.CookieContainer CookieContainer {
- get {
- System.ServiceModel.Channels.IHttpCookieContainerManager httpCookieContainerManager = this.InnerChannel.GetProperty<System.ServiceModel.Channels.IHttpCookieContainerManager>();
- if ((httpCookieContainerManager != null)) {
- return httpCookieContainerManager.CookieContainer;
- }
- else {
- return null;
- }
- }
- set {
- System.ServiceModel.Channels.IHttpCookieContainerManager httpCookieContainerManager = this.InnerChannel.GetProperty<System.ServiceModel.Channels.IHttpCookieContainerManager>();
- if ((httpCookieContainerManager != null)) {
- httpCookieContainerManager.CookieContainer = value;
- }
- else {
- throw new System.InvalidOperationException("Unable to set the CookieContainer. Please make sure the binding contains an HttpC" +
- "ookieContainerBindingElement.");
- }
- }
- }
- */
-
- public event System.EventHandler<GetDataCompletedEventArgs> GetDataCompleted;
-
- public event System.EventHandler<System.ComponentModel.AsyncCompletedEventArgs> OpenCompleted;
-
- public event System.EventHandler<System.ComponentModel.AsyncCompletedEventArgs> CloseCompleted;
-
- [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
- System.IAsyncResult WebServiceMoonlightTest.ServiceReference1.IService1.BeginGetData(System.AsyncCallback callback, object asyncState) {
- return base.Channel.BeginGetData(callback, asyncState);
- }
-
- [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
- object WebServiceMoonlightTest.ServiceReference1.IService1.EndGetData(System.IAsyncResult result) {
- return base.Channel.EndGetData(result);
- }
-
- private System.IAsyncResult OnBeginGetData(object[] inValues, System.AsyncCallback callback, object asyncState) {
- return ((WebServiceMoonlightTest.ServiceReference1.IService1)(this)).BeginGetData(callback, asyncState);
- }
-
- private object[] OnEndGetData(System.IAsyncResult result) {
- object retVal = ((WebServiceMoonlightTest.ServiceReference1.IService1)(this)).EndGetData(result);
- return new object[] {
- retVal};
- }
-
- private void OnGetDataCompleted(object state) {
- if ((this.GetDataCompleted != null)) {
- InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
- this.GetDataCompleted(this, new GetDataCompletedEventArgs(e.Results, e.Error, e.Cancelled, e.UserState));
- }
- }
-
- public void GetDataAsync() {
- this.GetDataAsync(null);
- }
-
- public void GetDataAsync(object userState) {
- if ((this.onBeginGetDataDelegate == null)) {
- this.onBeginGetDataDelegate = new BeginOperationDelegate(this.OnBeginGetData);
- }
- if ((this.onEndGetDataDelegate == null)) {
- this.onEndGetDataDelegate = new EndOperationDelegate(this.OnEndGetData);
- }
- if ((this.onGetDataCompletedDelegate == null)) {
- this.onGetDataCompletedDelegate = new System.Threading.SendOrPostCallback(this.OnGetDataCompleted);
- }
- base.InvokeAsync(this.onBeginGetDataDelegate, null, this.onEndGetDataDelegate, this.onGetDataCompletedDelegate, userState);
- }
-
- private System.IAsyncResult OnBeginOpen(object[] inValues, System.AsyncCallback callback, object asyncState) {
- return ((System.ServiceModel.ICommunicationObject)(this)).BeginOpen(callback, asyncState);
- }
-
- private object[] OnEndOpen(System.IAsyncResult result) {
- ((System.ServiceModel.ICommunicationObject)(this)).EndOpen(result);
- return null;
- }
-
- private void OnOpenCompleted(object state) {
- if ((this.OpenCompleted != null)) {
- InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
- this.OpenCompleted(this, new System.ComponentModel.AsyncCompletedEventArgs(e.Error, e.Cancelled, e.UserState));
- }
- }
-
- public void OpenAsync() {
- this.OpenAsync(null);
- }
-
- public void OpenAsync(object userState) {
- if ((this.onBeginOpenDelegate == null)) {
- this.onBeginOpenDelegate = new BeginOperationDelegate(this.OnBeginOpen);
- }
- if ((this.onEndOpenDelegate == null)) {
- this.onEndOpenDelegate = new EndOperationDelegate(this.OnEndOpen);
- }
- if ((this.onOpenCompletedDelegate == null)) {
- this.onOpenCompletedDelegate = new System.Threading.SendOrPostCallback(this.OnOpenCompleted);
- }
- base.InvokeAsync(this.onBeginOpenDelegate, null, this.onEndOpenDelegate, this.onOpenCompletedDelegate, userState);
- }
-
- private System.IAsyncResult OnBeginClose(object[] inValues, System.AsyncCallback callback, object asyncState) {
- return ((System.ServiceModel.ICommunicationObject)(this)).BeginClose(callback, asyncState);
- }
-
- private object[] OnEndClose(System.IAsyncResult result) {
- ((System.ServiceModel.ICommunicationObject)(this)).EndClose(result);
- return null;
- }
-
- private void OnCloseCompleted(object state) {
- if ((this.CloseCompleted != null)) {
- InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
- this.CloseCompleted(this, new System.ComponentModel.AsyncCompletedEventArgs(e.Error, e.Cancelled, e.UserState));
- }
- }
-
- public void CloseAsync() {
- this.CloseAsync(null);
- }
-
- public void CloseAsync(object userState) {
- if ((this.onBeginCloseDelegate == null)) {
- this.onBeginCloseDelegate = new BeginOperationDelegate(this.OnBeginClose);
- }
- if ((this.onEndCloseDelegate == null)) {
- this.onEndCloseDelegate = new EndOperationDelegate(this.OnEndClose);
- }
- if ((this.onCloseCompletedDelegate == null)) {
- this.onCloseCompletedDelegate = new System.Threading.SendOrPostCallback(this.OnCloseCompleted);
- }
- base.InvokeAsync(this.onBeginCloseDelegate, null, this.onEndCloseDelegate, this.onCloseCompletedDelegate, userState);
- }
-
- /*
- protected override WebServiceMoonlightTest.ServiceReference1.IService1 CreateChannel() {
- return new Service1ClientChannel(this);
- }
-
- private class Service1ClientChannel : ChannelBase<WebServiceMoonlightTest.ServiceReference1.IService1>, WebServiceMoonlightTest.ServiceReference1.IService1 {
-
- public Service1ClientChannel(System.ServiceModel.ClientBase<WebServiceMoonlightTest.ServiceReference1.IService1> client) :
- base(client) {
- }
-
- public System.IAsyncResult BeginGetData(System.AsyncCallback callback, object asyncState) {
- object[] _args = new object[0];
- System.IAsyncResult _result = base.BeginInvoke("GetData", _args, callback, asyncState);
- return _result;
- }
-
- public object EndGetData(System.IAsyncResult result) {
- object[] _args = new object[0];
- object _result = ((object)(base.EndInvoke("GetData", _args, result)));
- return _result;
- }
- }
- */
- }
- }
|