tomkuijsten / restup

Webserver for universal windows platform (UWP) apps
MIT License
114 stars 48 forks source link

Serialize xml: XML declaration returns utf-16 versus utf-8 #119

Open alwendt4 opened 7 years ago

alwendt4 commented 7 years ago

I send a get request from my client with the Accept-Charset = UTF-8, but the xml declaration encoding attribute is set to UTF-16.

Here is what my response body xml looks like:

\<?xml version="1.0" encoding="utf-16" ?>

..." Here is the object that is being serialized in .net: [XmlRoot(ElementName ="picture", Namespace = "")] public sealed class picture { [XmlAttribute(AttributeName = "filename")] public string filename { get; set; } [XmlText] public String ImageBytesBase64String { get; set; } } How do I get the xml root node encoding attribute set to "utf-8"?
Jark commented 7 years ago

Hi @alwendt4,

It looks like the uwp version of the XmlSerializer doesn't have the option to pass in the encoding so it's not an easy fix.

I'll look at this in more detail tomorrow, hopefully I can put a fix in then as well.

Thanks for reporting this.

Cheers,

Jark

alwendt4 commented 7 years ago

You are very welcome, Jark. Thanks for all of your hard work and saving me the time in not having to write my own RESTful webserver myself.

Also, if there is any way I can control the ability to remove the namespaces on the root node, that would be cool ... but not critical (like the encoding attribute). To be specific, I'm talking about the attributes:

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ... and the ... xmlns:xsd="http://www.w3.org/2001/XMLSchema" on the element in my sample above.

... the engineers tell me that it's not that important, but who knows what they will pick at next.

However, I'd rather the encoding attribute gets fixed so I can reload your package from NuGet as soon as possible, please. I've been told that this is the last obstacle in getting our prototype running, so I'm very excited.

One final question ... would I be able to download the source, compile it, and use Restup from the code I compile into a stand-alone UWP application, or is Restup something I have to use from a NuGet package installed in Visual Studio (sorry if this is a dumb question)?

Jark commented 7 years ago

Hi @alwendt4,

We're probably not going to add the functionality for specifying to removing namespaces, what might be useful at some point would be to able to specify the namespaces, but I don't think we'll commit to that right now. We're always open to code submissions though :)

I've added a pull request (#120) that should fix the issue.

When a NuGet package is available I can't promise you, @tomkuijsten usually takes care of that and it's dependent on his time schedule, so it might be a couple of weeks before they're available. In the mean time you can manually build them by cloning / downloading my development branch on https://github.com/jark/restup/tree/development, build the solution and use the dlls from that build in your project.

To answer your last question: any build/deploy method should copy the restup / any referenced dlls either next to the executable or in the package (.appx).

alwendt4 commented 7 years ago

FYI: I added the project directories: HttpMessage, WebServer, WebServerLogging, and Webserver.Models to a new solution (Background Application (IoT)). It compiled fine, but then when I added the DLLs {Restup.WebServer.dll, Restup.Webserver.Models.winmd}, and the using statements:

using Restup.Webserver.File; using Restup.Webserver.Http; using Restup.Webserver.Rest;

using Restup.Webserver.Attributes; using Restup.Webserver.Models.Contracts; using Restup.Webserver.Models.Schemas; using System.Threading.Tasks; using Windows.Foundation;

... I got an error about the \WebServer\bin\ARM\Debug\Restup.Webserver.Models\About.txt not existing. I simply added an empty About.txt text file and the compile error abated.

Additionally, event though I added the Restup.Webserver.Models.winmd reference to my solution, I couldn't shake the compiler warning: Could not resolve this reference. Could not locate the assembly "Restup.Webserver.Models". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

... any advice?

alwendt4 commented 7 years ago

Additionally, I finally got the modules to compile and work with a simple headless application. The breakpoints in my controller class were hitting, but I was getting "No response" returned from the client. So do you have step-by-step instructions for building a deployable app using your source code?

Jark commented 7 years ago

There's some information on the wiki, like the one-pager (https://github.com/tomkuijsten/restup/wiki/One-pager).

Usually when you don't get a response back this means you're not keeping an instance of the http server alive / not asking the background task to stay alive (what's called a deferral).

Try looking at the sample -> https://github.com/tomkuijsten/restup/blob/master/src/HeadlessDemo/StartupTask.cs and see what you have different to the sample.

Building a deployable app using our source code shouldn't be any different then the usual process for your chosen platform, so we don't provide any instructions for that, sorry.

alwendt4 commented 7 years ago

Jark ... I tried everything. I can't get a response. Can you get @tomkuijsten to do a push and create a package soon, please?

tomkuijsten commented 7 years ago

I try to take a look at the PR later tonight, bear with me.

alwendt4 commented 7 years ago

@tomkuijsten. You rock! Thank you very much.

tomkuijsten commented 7 years ago

Will get to it tomorrow, got a bit late at home today.

alwendt4 commented 7 years ago

Come on @tomkuijsten! You're slow like an old woman!

alwendt4 commented 7 years ago

@tomkuijsten, I was just kidding with my last comment. I wanted to make you laugh. Any progress, please?

tomkuijsten commented 7 years ago

Take a look at the PR #120

alwendt4 commented 7 years ago

@tomkuijsten thank you. But when I go to the NuGet - Solution Package manager in visual Studio I don't see an updated version. All I see is: Latest stable 1.0.0 (installed), and some other versions: 1.0.0, 1.0.0-rc1, 1.0.0-beta4, 1.0.0-beta2, etc.
image

In PR #120 you were talking about "1.0.1-beta1", but I don't see it. I couldn't get restup to work by downloading and compiling source into DLLs (and you don't have instructions for that), only by installing the package through NuGet in Visual Studio. Can you advise?

tomkuijsten commented 7 years ago

Yes, it's not published yet. You could download the package from the build output. The name of the package is not correct however, have to fix that, I hope tonight.

alwendt4 commented 7 years ago

Me again. Hummm. I tried to install the package found in "build output" by downloading and installing locally, and it failed. Here is the error (btw: I also installed the logging .nupkg first):

Restoring packages for 'BackgroundApplication1'. Restoring packages for C:\Users\mx8yqv\Desktop\Test3\BackgroundApplication1\BackgroundApplication1\project.json... GET https://api.nuget.org/v3-flatcontainer/webserver.logging/index.json GET https://api.nuget.org/v3-flatcontainer/webserver.models/index.json NotFound https://api.nuget.org/v3-flatcontainer/webserver.logging/index.json 142ms NotFound https://api.nuget.org/v3-flatcontainer/webserver.models/index.json 147ms Unable to resolve 'WebServer.Logging (>= 1.0.0)' for 'UAP,Version=v10.0'. Unable to resolve 'WebServer.Models (>= 1.0.0)' for 'UAP,Version=v10.0'. Package restore failed for 'BackgroundApplication1'. Package restore failed. Rolling back package changes for 'BackgroundApplication1'. ========== Finished ========== Time Elapsed: 00:00:00.6453987

tomkuijsten commented 7 years ago

I'll take a look at it tonight

alwendt4 commented 7 years ago

@tomkuijsten, any progress ??? ... I hate to sound pushy, and I really appreciate your work ... but I'm trying to get our prototype, which uses RESTUP, to the next phase and the UTF-16/UTF-8 thing is the only thing holding us up.

tomkuijsten commented 7 years ago

@alwendt4 I understand your frustration :) I think this will help, latest build package should work (you don't need the logging package, is the same as on nuget).

alwendt4 commented 7 years ago

@tomkuijsten, You did it!!!!!!!!! UTF-8, just like I wanted! Thank you very much, you're terrific!!!!! I can't find your direct contact off of GitHub. Please send it to me however you can, and I will send you updates as to how are project is going. I recommend you do. I have not disclosed who I work for. Al

tomkuijsten commented 7 years ago

@Jark did it, I only created the package, but good to hear it's working for you. We will discuss how we will publish this to nuget.

tomkuijsten commented 7 years ago

@alwendt4 still working? :)

alwendt4 commented 7 years ago

Still working great. Really appreciate your help. I couldn't have done it without you, and had you not moved so quick, I would have been in a real bind. We have what we need now. Thanks again.

The prototype is in position to be readied into a functional application prototype with all components assembled. Your Restup component was used to send network commands and command responses between a Windows machine and a Raspberry Pi 3 loaded with IoT.

Full disclosure: On June 12-13 your Restup module will be included as part of an application used in an internal Siemens employee competition called the "Siemens Hackathon" held on June 12-13.

I am an Advanced Software Engineer over here and I have several robotics engineers and a medical device manufacturing engineer on the team I am leading.

The overall objective will be to produce low-cost robotics components compatible with one of Siemens leading manufacturing software control systems for the purpose of highly inexpensive robotic device prototypes. So basically any robotic device you can build with Raspberry Pi with IoT loaded can be integrated into one of Siemens leading commercial manufacturing execution systems.

Al


From: Tom Kuijsten notifications@github.com Sent: Wednesday, June 7, 2017 5:41 AM To: tomkuijsten/restup Cc: alwendt4; Mention Subject: Re: [tomkuijsten/restup] Serialize xml: XML declaration returns utf-16 versus utf-8 (#119)

@alwendt4https://github.com/alwendt4 still working? :)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/tomkuijsten/restup/issues/119#issuecomment-306744833, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AWPjlQwGbjzRpBLCuS8mpqqoJx_M1m1dks5sBnBBgaJpZM4NbjD8.