Skip serialization when the return type is void.
authorAtsushi Eno <atsushi@ximian.com>
Wed, 24 Aug 2011 19:14:48 +0000 (12:14 -0700)
committerAtsushi Eno <atsushi@ximian.com>
Wed, 24 Aug 2011 19:14:48 +0000 (12:14 -0700)
This batch should fix bug #206.

mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/WebMessageFormatter.cs
mcs/class/System.ServiceModel.Web/Test/System.ServiceModel.Description/BugX206.cs [new file with mode: 0644]
mcs/class/System.ServiceModel.Web/Test/System.ServiceModel.Dispatcher/WebHttpDispatchOperationSelectorTest.cs

index 1186c9828569ef5b8a910062b2c9e6b1942d79d6..9b1b372a13d3bdeea6a43416ff03e14ac441f42d 100644 (file)
@@ -3,6 +3,7 @@
 //
 // Author:
 //     Atsushi Enomoto  <atsushi@ximian.com>
+//     Atsushi Enomoto  <atsushi@xamarin.com>
 //
 // Copyright (C) 2008,2009 Novell, Inc (http://www.novell.com)
 // Copyright (C) 2011 Xamarin, Inc (http://xamarin.com)
@@ -201,6 +202,9 @@ namespace System.ServiceModel.Dispatcher
 
                protected XmlObjectSerializer GetSerializer (WebContentFormat msgfmt, bool isWrapped, MessagePartDescription part)
                {
+                       if (part.Type == typeof (void))
+                               return null; // no serialization should be done.
+
                        switch (msgfmt) {
                        case WebContentFormat.Xml:
                                if (xml_serializer == null)
@@ -227,6 +231,9 @@ namespace System.ServiceModel.Dispatcher
                        // FIXME: handle ref/out parameters
 
                        var reader = message.GetReaderAtBodyContents ();
+                       reader.MoveToContent ();
+
+                       bool wasEmptyElement = reader.IsEmptyElement;
 
                        if (isWrapped) {
                                if (fmt == WebContentFormat.Json)
@@ -235,9 +242,9 @@ namespace System.ServiceModel.Dispatcher
                                        reader.ReadStartElement (md.Body.WrapperName, md.Body.WrapperNamespace);
                        }
 
-                       var ret = ReadObjectBody (serializer, reader);
+                       var ret = (serializer == null) ? null : ReadObjectBody (serializer, reader);
 
-                       if (isWrapped)
+                       if (isWrapped && !wasEmptyElement)
                                reader.ReadEndElement ();
 
                        return ret;
diff --git a/mcs/class/System.ServiceModel.Web/Test/System.ServiceModel.Description/BugX206.cs b/mcs/class/System.ServiceModel.Web/Test/System.ServiceModel.Description/BugX206.cs
new file mode 100644 (file)
index 0000000..eb1c8d5
--- /dev/null
@@ -0,0 +1,321 @@
+// 
+// This code was partly auto-generated by slsvcutil, version 4.0.60310.0
+// 
+namespace DHIWebService
+{
+    using System.Runtime.Serialization;
+    
+    
+    [System.Diagnostics.DebuggerStepThroughAttribute()]
+    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
+    [System.Runtime.Serialization.DataContractAttribute(Name="ClientLoginData", Namespace="http://schemas.datacontract.org/2004/07/Domain.Models")]
+    public partial class ClientLoginData : object
+    {
+        
+        private int CompanyNumberField;
+        
+        private string InstitutionIdField;
+        
+        private string PasswordField;
+        
+        private string UserNameField;
+        
+        [System.Runtime.Serialization.DataMemberAttribute()]
+        public int CompanyNumber
+        {
+            get
+            {
+                return this.CompanyNumberField;
+            }
+            set
+            {
+                this.CompanyNumberField = value;
+            }
+        }
+        
+        [System.Runtime.Serialization.DataMemberAttribute()]
+        public string InstitutionId
+        {
+            get
+            {
+                return this.InstitutionIdField;
+            }
+            set
+            {
+                this.InstitutionIdField = value;
+            }
+        }
+        
+        [System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]
+        public string Password
+        {
+            get
+            {
+                return this.PasswordField;
+            }
+            set
+            {
+                this.PasswordField = value;
+            }
+        }
+        
+        [System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]
+        public string UserName
+        {
+            get
+            {
+                return this.UserNameField;
+            }
+            set
+            {
+                this.UserNameField = value;
+            }
+        }
+    }
+    
+    [System.Diagnostics.DebuggerStepThroughAttribute()]
+    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
+    [System.Runtime.Serialization.DataContractAttribute(Name="Login", Namespace="http://schemas.datacontract.org/2004/07/Domain.Models")]
+    public partial class Login : object
+    {
+        
+        private int CompanyNumberField;
+        
+        private string InstitutionIdField;
+        
+        private string PasswordField;
+        
+        private string UserNameField;
+        
+        [System.Runtime.Serialization.DataMemberAttribute()]
+        public int CompanyNumber
+        {
+            get
+            {
+                return this.CompanyNumberField;
+            }
+            set
+            {
+                this.CompanyNumberField = value;
+            }
+        }
+        
+        [System.Runtime.Serialization.DataMemberAttribute()]
+        public string InstitutionId
+        {
+            get
+            {
+                return this.InstitutionIdField;
+            }
+            set
+            {
+                this.InstitutionIdField = value;
+            }
+        }
+        
+        [System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]
+        public string Password
+        {
+            get
+            {
+                return this.PasswordField;
+            }
+            set
+            {
+                this.PasswordField = value;
+            }
+        }
+        
+        [System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]
+        public string UserName
+        {
+            get
+            {
+                return this.UserNameField;
+            }
+            set
+            {
+                this.UserNameField = value;
+            }
+        }
+    }
+    
+    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
+    [System.ServiceModel.ServiceContractAttribute(Namespace="IBEWebSvc", ConfigurationName="DHIWebService.IDHIService")]
+    public interface IDHIService
+    {
+        
+        [System.ServiceModel.OperationContractAttribute(AsyncPattern=true, Action="IBEWebSvc/IDHIService/Login", ReplyAction="IBEWebSvc/IDHIService/LoginResponse")]
+       // FIXME: uncommenting this results in cryptic error message. We should tell what could be wrong here.
+//             [System.ServiceModel.Web.WebInvoke(BodyStyle=System.ServiceModel.Web.WebMessageBodyStyle.Wrapped)]
+        System.IAsyncResult BeginLogin(DHIWebService.LoginRequest request, System.AsyncCallback callback, object asyncState);
+        
+        DHIWebService.LoginResponse EndLogin(System.IAsyncResult result);
+        
+        [System.ServiceModel.OperationContractAttribute(Action="IBEWebSvc/IDHIService/Login", ReplyAction="IBEWebSvc/IDHIService/LoginResponse")]
+               [System.ServiceModel.Web.WebInvoke(BodyStyle=System.ServiceModel.Web.WebMessageBodyStyle.Wrapped)]
+        DHIWebService.LoginResponse Login(DHIWebService.LoginRequest request);
+        
+        
+    }
+    
+    [System.Diagnostics.DebuggerStepThroughAttribute()]
+    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
+    [System.ServiceModel.MessageContractAttribute(WrapperName="Login", WrapperNamespace="IBEWebSvc", IsWrapped=true)]
+    public partial class LoginRequest
+    {
+        
+        [System.ServiceModel.MessageBodyMemberAttribute(Namespace="IBEWebSvc", Order=0)]
+        public DHIWebService.ClientLoginData clientLoginData;
+        
+        [System.ServiceModel.MessageBodyMemberAttribute(Namespace="IBEWebSvc", Order=1)]
+        public DHIWebService.Login credentials;
+        
+        public LoginRequest()
+        {
+        }
+        
+        public LoginRequest(DHIWebService.ClientLoginData clientLoginData, DHIWebService.Login credentials)
+        {
+            this.clientLoginData = clientLoginData;
+            this.credentials = credentials;
+        }
+    }
+    
+    [System.Diagnostics.DebuggerStepThroughAttribute()]
+    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
+    [System.ServiceModel.MessageContractAttribute(WrapperName="LoginResponse", WrapperNamespace="IBEWebSvc", IsWrapped=true)]
+    public partial class LoginResponse
+    {
+    }
+    
+    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
+    public interface IDHIServiceChannel : DHIWebService.IDHIService, System.ServiceModel.IClientChannel
+    {
+    }
+    
+    [System.Diagnostics.DebuggerStepThroughAttribute()]
+    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
+    public partial class LoginCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs
+    {
+        
+        private object[] results;
+        
+        public LoginCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) : 
+                base(exception, cancelled, userState)
+        {
+            this.results = results;
+        }
+        
+        public DHIWebService.LoginResponse Result
+        {
+            get
+            {
+                base.RaiseExceptionIfNecessary();
+                return ((DHIWebService.LoginResponse)(this.results[0]));
+            }
+        }
+    }
+    
+    [System.Diagnostics.DebuggerStepThroughAttribute()]
+    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
+    public partial class DHIServiceClient : System.ServiceModel.ClientBase<DHIWebService.IDHIService>, DHIWebService.IDHIService
+    {
+        
+        private BeginOperationDelegate onBeginLoginDelegate;
+        
+        private EndOperationDelegate onEndLoginDelegate;
+        
+        private System.Threading.SendOrPostCallback onLoginCompletedDelegate;
+        
+        public DHIServiceClient()
+        {
+        }
+        
+        public DHIServiceClient(string endpointConfigurationName) : 
+                base(endpointConfigurationName)
+        {
+        }
+        
+        public DHIServiceClient(string endpointConfigurationName, string remoteAddress) : 
+                base(endpointConfigurationName, remoteAddress)
+        {
+        }
+        
+        public DHIServiceClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
+                base(endpointConfigurationName, remoteAddress)
+        {
+        }
+        
+        public DHIServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
+                base(binding, remoteAddress)
+        {
+        }
+        
+        public event System.EventHandler<LoginCompletedEventArgs> LoginCompleted;
+        
+        [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
+        System.IAsyncResult DHIWebService.IDHIService.BeginLogin(DHIWebService.LoginRequest request, System.AsyncCallback callback, object asyncState)
+        {
+            return base.Channel.BeginLogin(request, callback, asyncState);
+        }
+        
+        [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
+        DHIWebService.LoginResponse DHIWebService.IDHIService.EndLogin(System.IAsyncResult result)
+        {
+            return base.Channel.EndLogin(result);
+        }
+        
+        private System.IAsyncResult OnBeginLogin(object[] inValues, System.AsyncCallback callback, object asyncState)
+        {
+            DHIWebService.LoginRequest request = ((DHIWebService.LoginRequest)(inValues[0]));
+            return ((DHIWebService.IDHIService)(this)).BeginLogin(request, callback, asyncState);
+        }
+        
+        private object[] OnEndLogin(System.IAsyncResult result)
+        {
+            DHIWebService.LoginResponse retVal = ((DHIWebService.IDHIService)(this)).EndLogin(result);
+            return new object[] {
+                    retVal};
+        }
+        
+        private void OnLoginCompleted(object state)
+        {
+            if ((this.LoginCompleted != null))
+            {
+                InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
+                this.LoginCompleted(this, new LoginCompletedEventArgs(e.Results, e.Error, e.Cancelled, e.UserState));
+            }
+        }
+        
+        public void LoginAsync(DHIWebService.LoginRequest request)
+        {
+            this.LoginAsync(request, null);
+        }
+        
+        public void LoginAsync(DHIWebService.LoginRequest request, object userState)
+        {
+            if ((this.onBeginLoginDelegate == null))
+            {
+                this.onBeginLoginDelegate = new BeginOperationDelegate(this.OnBeginLogin);
+            }
+            if ((this.onEndLoginDelegate == null))
+            {
+                this.onEndLoginDelegate = new EndOperationDelegate(this.OnEndLogin);
+            }
+            if ((this.onLoginCompletedDelegate == null))
+            {
+                this.onLoginCompletedDelegate = new System.Threading.SendOrPostCallback(this.OnLoginCompleted);
+            }
+            base.InvokeAsync(this.onBeginLoginDelegate, new object[] {
+                        request}, this.onEndLoginDelegate, this.onLoginCompletedDelegate, userState);
+        }
+        
+        
+        [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
+        DHIWebService.LoginResponse DHIWebService.IDHIService.Login (DHIWebService.LoginRequest request)
+        {
+            return base.Channel.Login(request);
+        }
+    }
+}
index 64e875be261bbb59b2272aca69d27f9d8a1be8cc..4507383fdd0dedfc676935542c3e6830cc837349 100644 (file)
@@ -256,6 +256,7 @@ namespace MonoTests.System.ServiceModel.Dispatcher
                {
                        var host = new WebServiceHost (typeof (Hello));
                        host.AddServiceEndpoint (typeof (IHello), new WebHttpBinding (), "http://localhost:37564/");
+                       host.Description.Behaviors.Find<ServiceDebugBehavior> ().IncludeExceptionDetailInFaults = true;
                        host.Open ();
                        try {
                                // run client