From 3d385eb2703cd030ad3f535322a51c1873de9a72 Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Wed, 24 Aug 2011 12:14:48 -0700 Subject: [PATCH] Skip serialization when the return type is void. This batch should fix bug #206. --- .../WebMessageFormatter.cs | 11 +- .../System.ServiceModel.Description/BugX206.cs | 321 +++++++++++++++++++++ .../WebHttpDispatchOperationSelectorTest.cs | 1 + 3 files changed, 331 insertions(+), 2 deletions(-) create mode 100644 mcs/class/System.ServiceModel.Web/Test/System.ServiceModel.Description/BugX206.cs diff --git a/mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/WebMessageFormatter.cs b/mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/WebMessageFormatter.cs index 1186c982856..9b1b372a13d 100644 --- a/mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/WebMessageFormatter.cs +++ b/mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/WebMessageFormatter.cs @@ -3,6 +3,7 @@ // // Author: // Atsushi Enomoto +// Atsushi Enomoto // // 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 index 00000000000..eb1c8d5b78f --- /dev/null +++ b/mcs/class/System.ServiceModel.Web/Test/System.ServiceModel.Description/BugX206.cs @@ -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 + { + + 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 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); + } + } +} diff --git a/mcs/class/System.ServiceModel.Web/Test/System.ServiceModel.Dispatcher/WebHttpDispatchOperationSelectorTest.cs b/mcs/class/System.ServiceModel.Web/Test/System.ServiceModel.Dispatcher/WebHttpDispatchOperationSelectorTest.cs index 64e875be261..4507383fdd0 100644 --- a/mcs/class/System.ServiceModel.Web/Test/System.ServiceModel.Dispatcher/WebHttpDispatchOperationSelectorTest.cs +++ b/mcs/class/System.ServiceModel.Web/Test/System.ServiceModel.Dispatcher/WebHttpDispatchOperationSelectorTest.cs @@ -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 ().IncludeExceptionDetailInFaults = true; host.Open (); try { // run client -- 2.11.4.GIT