mikeobrien / WcfRestContrib

The WCF REST Contrib library adds additional functionality to the current WCF REST implementation.
MIT License
49 stars 18 forks source link

XML exception reading message body in .NET 4.5 #16

Open NorthNick opened 12 years ago

NorthNick commented 12 years ago

One of our servers was recently upgraded to .NET 4.5 and my .NET 4.0 WcfRestContrib app broke when processing a POST request with a simple text body. The error coming out is:

Error.Message=System.Xml.XmlException%3a+%27Text%27+is+an+invalid+XmlNodeType. %0d%0a+++at+System.Xml.XmlReader.ReadEndElement() %0d%0a+++at+WcfRestContrib.ServiceModel.Dispatcher.WebDispatchFormatter.Deserialize(Message+message%2c+WebFormatterFactory+formatterFactory%2c+Object%5b%5d%26+parameters%2c+RequestMessagePartDescription%5b%5d+requestParameters%2c+String+contentType)+in+d%3a%5cTeamCity%5cBuildAgent%5cwork%5cdac2ac50c21c000f%5csrc%5cWcfRestContrib%5cServiceModel%5cDispatcher%5cWebDispatchFormatter.cs%3aline+149 %0d%0a+++at+WcfRestContrib.ServiceModel.Dispatcher.WebDispatchFormatter.DeserializeRequest(Message+message%2c+Object%5b%5d+parameters)+in+d%3a%5cTeamCity%5cBuildAgent%5cwork%5cdac2ac50c21c000f%5csrc%5cWcfRestContrib%5cServiceModel%5cDispatcher%5cWebDispatchFormatter.cs%3aline+73% 0d%0a+++at+System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc%26+rpc) %0d%0a+++at+System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc%26+rpc) %0d%0a+++at+System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc%26+rpc) %0d%0a+++at+System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc%26+rpc) %0d%0a+++at+System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean+isOperationContextSet)&Error.Status=500

The error is in BInaryBodyReader.cs, at line 15 and the date it's trying to deserialise is a byte stream corresponding to the request body which, for what it's worth, is:

source=TweetDeck&screen%5Fname=d%5Froberts&text=Testing%20Zeitgeist

At this point I'm a bit stuck on how to proceed as I've been unable to find this sort of thing mentioned in any of the .NET 4.5 breaking changes. Any ideas or solutions would be very welcome. Many thanks,

Nick North

PS I am using the WcfRestContrib 1.7.10.0 NuGet package.

PPS I have just realised something else that may be important. I have my own reader for application/x-www-form-encoded data (which this request has as its content type), which is declared with the attributes on the service below. It looks as though my reader is not being invoked.

// Set this as the default MIME type because WCFRestContrib tries to match the entire Content-Type, which includes the boundary string for multipart/form-data
// so cannot be matched, as that is random. We happen to know that anything that is not application/x-www-form-urlencoded is multipart/form-data, so the trick
// works. 
[WebDispatchFormatterConfiguration("multipart/form-data")]
[WebDispatchFormatterMimeType(typeof(FormEncodedFormatter), "application/x-www-form-urlencoded")]
mikeobrien commented 12 years ago

I'm not really sure on that, we haven't upgraded yet.

We're actually in the process of migrating off of WCF right now so I'm not going to be involved much with this project anymore.

NorthNick commented 12 years ago

I'm sorry to hear you won't be invovled in the project anymore. I'll go and see if the problem is easy to fix, or if I should bite the bullet and move to the ASP.NET Web API. i will probably do the latter.

Many thanks for all your work on WcfRestContrib. My REST service would have been impossible without it, so it has been incrdibly useful to me.

Nick North

On 24 October 2012 15:44, mikeobrien notifications@github.com wrote:

I'm not really sure on that, we haven't upgraded yet.

We're actually in the process of migrating off of WCF right now so I'm not going to be involved much with this project anymore.

— Reply to this email directly or view it on GitHubhttps://github.com/mikeobrien/WcfRestContrib/issues/16#issuecomment-9742010.

mikeobrien commented 12 years ago

Yeah, I'm tired of dealing with WCF, especially since there are so many other better frameworks out there for doing REST. I bet you'll get a lot more mileage out of the web api.

Glad it helped you out! :)