Bug 13053 - Result StatusCode set in IDispatchMessageInspector.BeforeSendReply is always overwritten for faults to 500
Summary: Result StatusCode set in IDispatchMessageInspector.BeforeSendReply is always ...
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Web.Services ()
Version: master
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-07-04 08:18 UTC by foka
Modified: 2013-07-04 09:58 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Server app that "returns" fault with 200 code (2.53 KB, text/plain)
2013-07-04 08:18 UTC, foka
Details
Client of Server (854 bytes, text/plain)
2013-07-04 08:19 UTC, foka
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 13053 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

Description foka 2013-07-04 08:18:11 UTC
Created attachment 4272 [details]
Server app that "returns" fault with 200 code

In WCF, for http responses you can set different StatusCodes by using custom IDispatchMessageInspector.BeforeSendReply.
In Mono, fault's StatusCode is always set to 500:
https://github.com/mono/mono/blob/master/mcs/class/System.ServiceModel/System.ServiceModel.Channels.Http/HttpRequestContext.cs#L156-L157
In MS.NET custom status codes also work for faults (expected). There's also a good explanation how to do it in order for Silverlight client to work with faults:
http://msdn.microsoft.com/en-us/library/ee844556(v=vs.95).aspx
Please, read short "HTTP status codes" section with an example. This example works on MS.NET (status code is 200) but it does not on mono (status code: 500).

I'm attaching sample Client and Server applications that demonstrates the issue. Compile it by:
mcs Server.cs -r:System.ServiceModel -r:System.Runtime.Serialization
mcs Client.cs -r:System.ServiceModel -r:System.Runtime.Serialization
Unfortunately the app doesn't print full response. You have to use some tool that shows http traffic, I'm using fiddler2 on Windows.


Response on Mono (Linux):

HTTP/1.1 500 Internal Server Error
Content-Type: text/xml; charset=utf-8
Server: Mono-HTTPAPI/1.0
Date: Thu, 04 Jul 2013 11:42:32 GMT
Content-Length: 596
Connection: close

<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Header><Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/IFooService/FooWithFaultMyFaultFault</Action></s:Header><s:Body><s:Fault><faultcode>Sender</faultcode><faultstring xml:lang="">My reason</faultstring><detail><MyFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/WcfServer.Contract"><Message>My fault message</Message></MyFault></detail></s:Fault></s:Body></s:Envelope>


Response on Windows (MS.NET runtime):

HTTP/1.1 200 OK
Content-Length: 387
Content-Type: text/xml; charset=utf-8
Server: Microsoft-HTTPAPI/2.0
Date: Thu, 04 Jul 2013 11:45:06 GMT

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><s:Fault><faultcode>s:Client</faultcode><faultstring xml:lang="pl-PL">My reason</faultstring><detail><MyFault xmlns="http://schemas.datacontract.org/2004/07/WcfServer.Contract" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Message>My fault message</Message></MyFault></detail></s:Fault></s:Body></s:Envelope>
Comment 1 foka 2013-07-04 08:19:02 UTC
Created attachment 4273 [details]
Client of Server
Comment 2 foka 2013-07-04 09:58:47 UTC
My proposal is to allow to overwrite default fault code (500) with custom code. Simple reorder of statements in HttpRequestContext.InternalReply works for me. This is my fix: https://github.com/foka/mono/commit/eada60fe0cd53a84fdcccb5bf10566bbd18d6100