1iveowl / Simple-Http-Listener-PCL

Simple Http Server PCL for Xamarin Forms
MIT License
39 stars 6 forks source link

Switching to Profile 111 #6

Closed falahati closed 8 years ago

falahati commented 8 years ago

Hey,

In past couple of days I used the library on Android, iOS, WinForm, UWP 10 and WPF. Didn't disappointed me at all :) But it failed on Windows 8.1 Store App despite being supported by Profile 7.

But I do like to ask for Windows 8.1 and Windows Phone 8.1 support. As both these platforms are very similar to UWP and sharing almost identical parts. So can I expect this library in Profile 111 any time soon? I know it is a lot to ask and I would write the code my self. But I am not very familiar with the Bait and Switch pattern.

Thanks again for developing this library.

1iveowl commented 8 years ago

Can you be more specific? How does it fail, do you get an Exception?

There are in fact some limitations in WinRT that means that there are scenarios that will only Work on UWP. This relates to SocketLite.PCL. See here: WinRT vs UWP

But, no I do not plan to support anything below Profile 7 and hence the library will not support Profile111.

falahati commented 8 years ago

Hey, When running under Win8.1; NotImplementedException raised. With this message:

This PCL uses the 'Bait and Switch pattern'. This blog post offers great insights into this pattern: http://log.paulbetts.org/the-bait-and-switch-pcl-trick/

at SocketLite.Services.TcpSocketListener.StartListeningAsync(Int32 port, ICommunicationInterface communicationInterface, Boolean allowMultipleBindToSamePort) at SimpleHttpServer.Service.HttpListener.d__19.MoveNext() --- End of stack trace from previous location where exception was thrown ---

I understand that, but if Win8.1 is on your support list, Windows Phone 8.1 can also be supported very easily.

What if I try to add the support and suggest a pull request, would you accept it?

Thanks

1iveowl commented 8 years ago

Might have been fixed in today's Nuget update. Plz try and let me know.

Win phone 8.1 is not supported but it might work after the update.

falahati commented 8 years ago

Still same error, btw, I am on version 2.x.x and I tried the 2.0.8

And about Windows Phone, well the problem goes more than support for now. It is impossible to add the nuget package to a WindowsPhone8.1 project because HttpMachine refuses to work under this environment. You need to update the nuget package of HttpMachine, Needless to say that I can install SocketLite.PCL on WP8.1 without problem. I didn't tested to see if it actually works tho.

falahati commented 8 years ago

PS: the reason I believe profile 111 is a good way to go is because it has the same set of tools as .NetStandard 1.1

1iveowl commented 8 years ago

So did it work with release 2.0.8?

Regarding backwards compat. I do these libraries as a hobby and because I use them myself. I also like to use the new stuff and to be frank I sort of dislike supporing the old.

Hence, all my Work going forward will be related to version 3+ of the library and will rest on .NET Standard 1.4 and beyond. However, feel free to fork the library and create any other versiojn you might like ;-)

falahati commented 8 years ago

Yeah, the only problem is that I hate to publish a NuGet package or put it next to my other project while your package is up and running well only for some minor changes. Anyway, if we failed here, I am gonna try to make the modifications and then try to convince you to add them to your repo :)

And no unfortunately it didn't. Exact same error as before with version 2.0.8. Can you take a look at this?

Before closing this topic entirely, can you modify HttpMachine to get installed on WP8.1? Shouldn't be hard as it does support (or should support based on spac) Windows 8.1. Then I can test the libraries on WP8.1 to see if they work. For now it seems that the both SocketLite.PCL and SimpleHttpListernet does support WP8.1 at least on paper. But HTTPMachine refuses to cooperate.

Thanks

falahati commented 8 years ago

@1iveowl Hi again, i really think that you can open this issue and it can be fixed for sure.

I compiled and checked different parts of the project. It seems that all of the libraries are compatible with Win8 and WinPhone8.1. The only problems are nuget packages.

For example for WinPhone 8.1 all you need to do is to make the HttpMachine library package compatible. Library itself supports this platform. In-fact, if I add the dll file manually I can use it in my project. SocketLite.PCL dll files are also compatible with WindowsPhone 8.1, but its nuget package don't reference the SocketLite.PCL.dll file and this should be referenced manually. I believe a little tweak to HttpMachine.PCL and SocketLite.PCL packages can make these two libraries compatible and there is no need for new code or even new compiling.

And as for Win8; situation is similar, unfortunately nuget package reference the wrong SocketLite.PCL.dll file (the portable one with no real implementation). Removing this reference and adding the correct dll file solves the error message described in this issue. So this also can be solved by fixing the nuget package of SocketLite.PCL.dll

As for profile 111, SocketLite.PCL can be added to the project, but it fails to add the SocketLite.PCL.dll file to references. Doing so manually can make the project works. This is also true for both SimpleHttpListener.PCL and HttpMachine.PCL packages. Even though you cant add these two packages to the project, if you reference them manually they work alright.

So now, its only about nuget re-uploading, support is already there. I hope that by now and with the above information, you decide to support these two nice and little expecting platforms and as result of these support, moving to Profile 111 as well :)

Good night

1iveowl commented 8 years ago

Thank you for the feedback. I see your point and I'll look into it.

Please give me a couple of days. It's a bit busy at the moment.

1iveowl commented 8 years ago

So HttpMachine v 1.1.3 is now Profile 111, while v.2.0.2 is .NET Standard 1.2. The two are otherwise identical.

Please test and let me know how that works for you and I'll look at the SimpleHttpListener next...

1iveowl commented 8 years ago

So I implemented Profile111 for SimpleHttpListener too. I really hope it worked. I know it looks easy, still it took me more than 2 hours in all update the dependency chain.

falahati commented 8 years ago

Thanks you for your work and I appreciate the time you put on this issue.

I can confirm that I can install all packages in all my projects now. But there is a big problem,

2>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3274: The primary reference "C:\Users\s_fal.nuget\packages\HttpMachine.PCL\1.1.3\lib\portable-net45+win8+wpa81\HttpMachine.dll" could not be resolved because it was built against the ".NETPortable,Version=v5.0" framework. This is a higher version than the currently targeted framework ".NETPortable,Version=v4.5,Profile=Profile111". 2>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3275: The primary reference "C:\Users\s_fal.nuget\packages\SimpleHttpListener\2.0.10\lib\portable-net45+win8+wpa81\SimpleHttpServer.dll" could not be resolved because it has an indirect dependency on the assembly "HttpMachine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" which was built against the ".NETPortable,Version=v5.0" framework. This is a higher version than the currently targeted framework ".NETPortable,Version=v4.5,Profile=Profile111". 2>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3274: The primary reference "C:\Users\s_fal.nuget\packages\SocketLite.PCL\2.0.9\lib\portable-net45+win8+wpa81\SocketLite.dll" could not be resolved because it was built against the ".NETPortable,Version=v4.6,Profile=Profile32" framework. This is a higher version than the currently targeted framework ".NETPortable,Version=v4.5,Profile=Profile111". 2>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3275: The primary reference "C:\Users\s_fal.nuget\packages\SimpleHttpListener\2.0.10\lib\portable-net45+win8+wpa81\SimpleHttpServer.dll" could not be resolved because it has an indirect dependency on the assembly "SocketLite, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" which was built against the ".NETPortable,Version=v4.6,Profile=Profile32" framework. This is a higher version than the currently targeted framework ".NETPortable,Version=v4.5,Profile=Profile111".

It seems that while repackaging, you upgraded the HttpMachine to a higher version. Even though I used version 1.x of HttpMachine, it seems that the packages binaries are of .NetStandard type and therefore not compatible with .NetPortable4.5. This is also true for SocketLite, it seems that you decided to compile it with .Net 4.6 and profile 32 (which BTW I don't understand why this is reported this way, profile 32 is a Win8, WinPhone8 only profile.) But I cant go over version 4.5 of .Net because I will loose lot of target platforms. This profiling thing and framework targeting is getting out of hand and I don't understand half of it. xD

This test was on a PLC library targeting .NETPortable,Version=v4.5,Profile=Profile111 (.Net4.5, Win8, .NetCore, WP8.1, Xamarin.Android, Xamarin.iOS, MonoTouch)

Thank you again

1iveowl commented 8 years ago

Yes, this is what I mean. It seems easy in theory but it is really quite a pain to get everything just right and aligned.

I'll look at it, but not tonight.

1iveowl commented 8 years ago

Oh and feel free to make Fork and a Pull Request of the Profile111 branch of SimpleHttpListener, Socket lite and HttpMachine and see if you can figure out what the problem is? 😉👍

falahati commented 8 years ago

Hey @1iveowl Why Simple-Http-Listener-PCL projects has an interface project? Its not based on bait and switch pattern and this seems unnecessarily. Would you accept if I merge them and propose a pull request? Regards,

1iveowl commented 8 years ago

Please keep the interface. Having it has nothing to do with Bait and Switch.

Have you found the cause of the bug?

falahati commented 8 years ago

Well I managed to make the nuget packaging process little tidier. In the process of doing so I wanted to see if I can make the package simpler by merging these two projects.

Then why we have the interface? You planing on expanding it somehow later?

1iveowl commented 8 years ago
  1. I like coding to an interface
  2. Someone can use the interface to make a different implementation
falahati commented 8 years ago

"I like coding to an interface" that's good reason enough for me :) You cant argue with that :)

I am gonna send the pull requests in next hour.

falahati commented 8 years ago

Ok, I proposed the changes, except nuget generation scripts, I made some small changes to other parts. I hope that you accept them.

I also tested the generated packages on a local repo and manages to get them working on all platforms. I do have some problems with WinPhone8.1 not actually receiving requests but it shouldn't be related to your projects. I need more time to figure out whats happening there.

Thanks

1iveowl commented 8 years ago

Great. I'll look at it tomorrow. Thanks

1iveowl commented 8 years ago

Thanks for the Nuget script. However I have some challenges using it.

When I run ./publish.ps1 I get this error:

Successfully created package 'NuGet\SocketLite.PCL.2.0.20.symbols.nupkg'. WARNING: No API Key was provided and no API Key could be found for 'http://packages.nuget.org/v1/FeedService.svc'. To sa ve an API Key for a source use the 'setApiKey' command. Pushing SocketLite.PCL.2.0.20.nupkg to 'http://packages.nuget.org/v1/FeedService.svc'... PUT http://packages.nuget.org/v1/FeedService.svc/ MethodNotAllowed http://packages.nuget.org/v1/FeedService.svc/ 622ms System.AggregateException: One or more errors occurred. ---> System.Net.Http.HttpRequestException: Response status code does not indicate success: 405 (Method Not Allowed). at NuGet.CommandLine.PushCommand.d16.MoveNext() --- End of inner exception stack trace --- at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at NuGet.CommandLine.Command.Execute() at NuGet.CommandLine.Program.MainCore(String workingDirectory, String[] args) ---> (Inner Exception #0) System.Net.Http.HttpRequestException: Response status code does not indicate success: 405 (Met hod Not Allowed). at NuGet.CommandLine.PushCommand.d16.MoveNext()<---

I have already added the API Key with nuget SetApiKey xzy...123. I searched a bit and found that mayby I should change the last line for the ps script to:

NuGet.exe push $version -Verbosity detailed -Source "http://packages.nuget.org"

This gets me past the api key error above but now I run into another challenge. I'm prompted for a username and password. I'm using a Microsoft Account to log in to Nuget. I know that password but so far I've not been able to figure out the right combination to make the login succeed.

Any hints?

falahati commented 8 years ago

Hi, Login and proceed to "https://www.nuget.org/account" page. At the end of the page there is a ApiKey section which helps you with that.

nuget.exe setApiKey xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx nuget.exe push MyPackage.1.0.nupkg -Source https://www.nuget.org/api/v2/package

Setting api key once on a machine is all you need to do.

Another useful page: http://blog.davidebbo.com/2011/03/saving-your-api-key-with-nugetexe.html

1iveowl commented 8 years ago

Thanks.

1iveowl commented 8 years ago

I accepted all your PR's and I've released updated Nuget. They pass my tests. Do they pass your tests?

falahati commented 8 years ago

They did, Thank you