Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
alwendt4 opened this issue May 15, 2017 · 23 comments
Open

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

alwendt4 opened this issue May 15, 2017 · 23 comments

Comments

@alwendt4
Copy link

alwendt4 commented May 15, 2017

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" ?>
<picture xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd="http://www.w3.org/2001/XMLSchema"filename="test.jpg">..."

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
Copy link
Collaborator

Jark commented May 15, 2017

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
Copy link
Author

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
Copy link
Collaborator

Jark commented May 16, 2017

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 alwendt4 changed the title Serialize xml and xml root node returns utf-16 versus utf-8 Serialize xml and xml declaration returns utf-16 versus utf-8 May 16, 2017
@alwendt4 alwendt4 changed the title Serialize xml and xml declaration returns utf-16 versus utf-8 Serialize xml: XML declaration returns utf-16 versus utf-8 May 16, 2017
@alwendt4
Copy link
Author

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
Copy link
Author

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
Copy link
Collaborator

Jark commented May 16, 2017

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
Copy link
Author

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
Copy link
Owner

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

@alwendt4
Copy link
Author

@tomkuijsten. You rock! Thank you very much.

@tomkuijsten
Copy link
Owner

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

@alwendt4
Copy link
Author

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

@alwendt4
Copy link
Author

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

@tomkuijsten
Copy link
Owner

Take a look at the PR #120

tomkuijsten added a commit that referenced this issue May 17, 2017
Serialize and deserialize with the correct encoding, fixes #119
@alwendt4
Copy link
Author

@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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

I'll take a look at it tonight

@alwendt4
Copy link
Author

alwendt4 commented May 19, 2017

@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
Copy link
Owner

@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
Copy link
Author

@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
Copy link
Owner

@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
Copy link
Owner

@alwendt4 still working? :)

@alwendt4
Copy link
Author

alwendt4 commented Jun 7, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants