Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Mr Shiny Pants
Nov 12, 2012
I am a big fan of curl for testing WCF/REST services.

Fiddler is also really, really good.

Adbot
ADBOT LOVES YOU

Mr Shiny Pants
Nov 12, 2012
Anyone here familiar with RX? I would like to ask some questions about it cause my understanding of it is severely lacking and documentation that I understand is hard to come by.

Mr Shiny Pants
Nov 12, 2012
Nice,

I am having a hard time finding resources on the net about the latest version of RX. An example being that FromAsyncPattern is deprecated and is now superseded by FromAsync. This is fine except a lot of blogs and examples still use the FromAsyncPattern.

So any pointers to resources that are up to date would be awesome.

I am at work now, when I get home I will try to make a better post.

Mr Shiny Pants
Nov 12, 2012
So I am writing a little server using HttpListener and it is working as it should.

Now I want to receive files and I can't figure out how to go about this.

HttpListener only exposes a requestbody stream and so I get only the raw stream to work with.

A POST includes a lot of extra information including a boundary between files.

Is there a way in the .Net framework where I can pass this stream into that does all this for me? Pass the stream into a HttpContent class or something.

Or am I going to be stripping the stream and extracting the data body manually? :confused:

Mr Shiny Pants
Nov 12, 2012

hewerman posted:

If you are writing this from scratch using HttpListener, I believe you're going to have to use the POST and the boundaries and pass them to some sort of StreamReader or FileStream. My only actual experience is with MVC, where it is much more convenient to get the list of files.

I was afraid of that, too bad you can't just pass an inputstream to some other base class and let it do the heavy lifting. HttpRequest.Files looked like a good candidate.

Seeing as this is for my own project I might even just pass the file directly into the inputstream and copying it 1 to 1 to a file. I can get the filename from the URL it is posted to.

Mr Shiny Pants
Nov 12, 2012

wwb posted:

IIRC you can self-host the new WebAPI stuff which might be exactly what you all are looking for here. The WebAPI is also open source so perhaps you can find the magics to do it yourself in their codes.

I don't know, I think WebApi needs a lot of extra "stuff" to get working, at least that is the general idea that I got from it. HTTP listener just needs HTTP.SYS and works pretty good on Mono.

I've looked at the NancyFX source and finally figured out how they extract the Byte stream from the Request.Inputstream. Now to code it up for myself. :)

At my level of coding this is pretty advanced stuff.

As for the stream: I figured I would filestream it to disk if over a certain size, this is what Nancy also does. Which made a me feel a little better because I thought of that before I saw it in their source.

The filestream would result in a seekable stream so I can extract the bytestream that contains the data from the inputstream. If it works like I hope it does it should keep memory usage down and perform pretty well. My experience with streams and the performance of them is limited to be honest. Any pointers or do's and don'ts are welcome :)

Mr Shiny Pants fucked around with this message at 00:28 on Feb 22, 2013

Mr Shiny Pants
Nov 12, 2012

wwb posted:

Interesting, wasn't aware of the mono angle. One thing you might look at then would be manos de mono (http://manosdemono.org/)

I've taken a look at Manos, it looks pretty good as a non blocking webserver. Another one is Kayak if I am not mistaken. The idea is to get this running through Mono on a Raspberry Pi. :)

Thanks for the tip.

Mr Shiny Pants
Nov 12, 2012
Thanks :) One of the biggest problems I found when programming, and I am pretty new to all of this, is not getting demotivated if things don't work.

So far, one of my biggest accomplishments is still working on the project. :)

Mr Shiny Pants
Nov 12, 2012
Well I've got my multipart stream decoding piece working, yay!

Streams are pretty nice :) Just remember to set the right position otherwise you'll be scratching your head figuring out why I doesn't work....

One nice thing about building it myself is that my understanding of what is happening has been greatly enhanced. This has lead to the removal of some code that was unnecessary making it all a bit simpler.

Mr Shiny Pants
Nov 12, 2012
Another vote for Plink, my friend uses it to automate his VMware backups on his home network. It's pretty powerful.

Mr Shiny Pants
Nov 12, 2012

zokie posted:

I'm having issues with ASP.NET MVC, when deployed to our ISS any first visit to the website is soo sloooow. Does anyone have the same experience and any idea of how to fix it?

It has to spin up everything so that takes awhile. For sharepoint there are warmup scripts that do this for you. A batch file doing a http request to your site should be sufficient to get everything "warmed-up" making request handling smoother for the first user.

IIS 7.5 contains logic to keep an application pool "warm" if I am not mistaken.

Mr Shiny Pants
Nov 12, 2012

Dietrich posted:

I wrote a windows service named SiteWarmer that issues requests to our various sites on a regular basis to keep them hot, all configurable from the app.config. It was a nice couple hour project.


This is true. I found that it was typical Microsoft first generation type functionality- super complicated for what 99.9% of people need. At some point I want to figure out how to use this, but it was faster and easier just to do the SiteWarmer service for me.

Cool, I wrote a little app that queries our SharePoint farm for all sites and subsites and queries them. I'll check your tool also, might come in handy for other things.

Mr Shiny Pants
Nov 12, 2012
I have a bit of a conceptual question regarding static classes vs regular ones and when to use them.

I have a small webserver that handles requests, these requests can contain files and need to be persisted to disk.
The logic for writing these streams is now handled by a static class so I don't have to keep a reference to the class in the HTTP handler logic.

I just do Datastore.persistfile(file) or whatever and it works.

Now I was wondering if I am going about this in the right way or that this is going to bite me down the road with threading or something. I can't oversee any holes I am digging for myself so to speak.

Any pointers or guidelines for this? A lot of stuff I've read over at stack overflow deals with singletons and whatnot but it is not really clear to me.

Now my own logic is that I don't need an instance of this class. I only need the one datastore for writing to disk, that's also a reason I made it static.

Thinking about this further and the reason for posting this question is that I have another problem with references to other classes. So I've been reading about dependency injection and inversion of control but this too advanced right now for me.

Conceptually I am thinking about it like this: A request comes in, gets instantiated into the proper request object, during this I inject a Datastore instance and any other class instances I might need to handle the request. Afterwards I dispose the lot.

Sounds ok?

Mr Shiny Pants fucked around with this message at 21:59 on Mar 27, 2013

Mr Shiny Pants
Nov 12, 2012

Stubb Dogg posted:

I would use two lists is in most cases, but you probably should look into something like Reactive Extensions (Rx) because I think it is good fit for what you're trying to do.

Especially if UI code is involved as Rx can help with dispatching events to UI thread for you.

Or you could use the new async/await methods, take the request and handle it using a task.

Mr Shiny Pants
Nov 12, 2012
Try running VS as administrator. Might be UAC tripping you up.

Mr Shiny Pants
Nov 12, 2012

wwb posted:

Why would UAC kick in for a remote network share?

That said, I'd try running publish from MSBuild from the command line with the verbose option to see what it is yammering about and when as that might clue you in.

Well I had problems with saving to my own UNC share because of it. Something about credentials not being shared between processes I guess.

Another thing that might bite you is that you are saving to an IP address and Windows treating it as a internet address. I had this problem with a VS extension that would not load. After copying it from my DFS redirected home directory it worked like a charm. My DFS directory was configured as a FQDN.

Putting the ip or FQDN in your intranet zone in IE likely fixes this.

Mr Shiny Pants fucked around with this message at 00:34 on Mar 30, 2013

Mr Shiny Pants
Nov 12, 2012

fankey posted:

Any suggestions for a .NET embedded web server? I'd prefer something that doesn't use HttpListener (http.sys) but handles the TCP/IP transfers natively because the server needs to use ephemeral ports which I don't think would be easy to do with a http.sys solution. http.sys also seems to either require running as Administrator or using netsh to configure it. All I need to do is serve up files and support basic auth on some of the files. I have my own hacked together HTTP server but it's unreliable with certain clients ( which doesn't surprise me ) and I figure it would take less time to integrate a well tested HTTP server than futz around with mine.

Things I've found-
  • Nancy - Uses http.sys
  • kayak - appears to be abandoned. No documentation
  • Griffin.WebServer - lots of 'Initial checking. Something is still buggy.' comments. No documentation. I did get it to serve up files nicely but have no idea how their authentication works.
  • C# WebServer - abandoned. No documentation for the latest version.

You can use the Mono one. It is HTTP listener but does not need to be run as administrator IIRC.

Mr Shiny Pants
Nov 12, 2012
Anyone have any experience with UPNP in .Net?

I want my program to open a port on a router so that it can accept incoming traffic on a random port.
I've looked for a good library and found Mono.nat. After turning on Upnp on my router it finds it but I can't get my external ip.

I've turned off the Windows firewall and during debugging I can see it communicating with the router but i have no clue how to interpret the returned data. Everything looks ok.

Mr Shiny Pants
Nov 12, 2012
Thanks, i'll take a look.

Would this code by any chance also work on Mono? I need to run this on Linux also :)

Edit: drat, that looks complicated.....

I have a bit of a dilemma, one the one hand it would be awesome that it would autoconfigure, on the other hand there are some completely broken UPNP servers making the event of it working as it should a bit of a crapshoot.

Maybe some old fashioned port forwarding would be enough. :)

Mr Shiny Pants fucked around with this message at 22:40 on Jan 23, 2014

Mr Shiny Pants
Nov 12, 2012
I would put it in something like an Item factory. When a new item is created the factory is responsible for setting the right SKU number.

Mr Shiny Pants
Nov 12, 2012

ninjeff posted:

Forgive me if I'm wrong, but this seems like what you actually want. The calculation should be different for different data stores, so that it doesn't take forever to run. Even in Mr Shiny Pants'/Dietrich's solution, you still need to write the IItemRepository query that the ItemFactory calls.

That also sounds plausible, if the SKU number is something that is dependent on the type of repository and not just a number for tracking/identification.

Mr Shiny Pants fucked around with this message at 17:52 on Jan 24, 2014

Mr Shiny Pants
Nov 12, 2012

Night Shade posted:

Are any of you guys using Service Bus for Windows Server? Any ideas how to get a service running as SYSTEM to authenticate against it?

If it is over the network it won't work, system is for the local machine. Configure your app to talk with the servicebus using a domain account.

configure the service to run as a user instead of localsystem.

Mr Shiny Pants
Nov 12, 2012

wwb posted:

^^^ if you don't have a domain handy then you can also use 2 similarly named / passworded windows accounts.

Yes, i forgot to mention this also works.

Mr Shiny Pants
Nov 12, 2012
For anyone struggling with IOC and DI ( like me ). This is the best explanation I have found:

https://www.youtube.com/watch?v=5lIeky2V4dc

It's pretty long but goes in great detail about WHY you want it.

Mr Shiny Pants
Nov 12, 2012

ljw1004 posted:

Gosh, I've not used IOC/DI myself, and after that video I strongly don't want to.

(1) His code had one bug (what happens if the clock ticks over to 8pm between his two if statements) but nothing in his testing framework helped found it. The bug was only accidentally fixed in his refactoring. To be honest, most of the bugs I face are race conditions. Maybe that's just because I try to create more interactive responsive or parallelized code than usual, or maybe I'm not as good at it than others, but all of the talk's IOC/DI seemed to making it harder to spot such issues.

(2) I usually output text to the console, save this into a "baseline.txt" file that I check in. Then when I make changes to the code I compare my new "results.txt" to the original. It's simply and robust and works well. By contrast he turned his code into spaghetti to achieve THE SAME functionality within unit tests. Why? (It looked like he also had to murder his public/internal accessibility to achieve it; I just stick my code into a test exe as a linked file, so it can keep its internal accessibility).

(3) All of it was motivated by wanting to test his code against DateTime.Now. But almost no code is sensitive to that kind of thing. Instead it's sensitive to the complex set of data that goes in, e.g. the Word document that you're loading, or the set of rows in your Azure table. These things are already naturally mockable (just by loading a different document, or pointing to a test database) so I don't see that it buys anything.



There's a saying in computer science that "every problem can be solved by adding a layer of indirection". My position is: "Adding a layer of indirection always creates more problems than it solves".

I found it helpful in that he created a narrative that explained why he was doing things. Even in simple programs you stumble on the classes depending on classes etc. etc. I quite like it, to each his own I guess but for making core concepts clear i thought it was pretty good.

Especially writing his own container and showing how IOC containers map constructors and how something "could" work was pretty nice.

Now I must be honest, it feels all a little cargo culty which seems to crop up a lot in IT actually. I mean it always something that is in vogue, IoC, Factory methods, fluent etc. etc. but i quite like this.

I can see where you're coming from.

Mr Shiny Pants fucked around with this message at 09:29 on Feb 7, 2014

Mr Shiny Pants
Nov 12, 2012

wwb posted:

We've got a little project that involves reading a bunch of PDFs and making them searchable. We can handle the whole "take bags of text and make it searchable" pretty easily but we are having some trouble with the reading PDFs end of the equation.

We've tried using PdfTextract which is a pretty thin wrapper on the last free version of PdfSharp before they went commercial with limited success. We have also tried Docotic.Pdf which seems to work but I really hate to pay $1k to read PDFs. Is there anything else out there that is reliable for less or better yet free*?

* money isn't really the problem, all the overhead of dealing with license components rubs me wrong and is a pain in the rear end with the CI setup we've got.

Well for making PDFs searchable Abby Finereader OCR is the best. For free: maybe the Adobe Ifilters for PDF?

Mr Shiny Pants
Nov 12, 2012

peepsalot posted:

Can it work in vista though? The signalr documentation omitted it from its list of supported server platforms, or is that only assuming you are going through IIS or whatever .NET web apps typically use.

HttpListener would do the trick in combination with Nancy. It uses http.sys and is supported from XP to 8.1.

If you don't want to run the application as administrator, which you must if you use httplistener otherwise it can't open up a port. You can use the Mono one. There is a nuget package for it.

Mr Shiny Pants
Nov 12, 2012

Ender.uNF posted:

I've always regretted using WCF.

From the overly abstract, insanely complex, half-undocumented configuration, to reliable sessions dropping their heartbeat under CPU load (also undocumented behavior), to the insanity that is channel aborts (even for minor transient errors), to the fact that *any* serialization error fast aborts the entire stack and closes the connection with a non-loggable, non-handlable error. Not to mention the half-assed unreliable duplex contract stuff. Oh and good luck figuring out exactly what knob to turn when messages start getting rejected for exceeding some limit. Is it in the service behavior? The client TCP limits? The object serializer? Who knows? gently caress you, that's who.


Don't use WCF kids. Seriously. The only people who don't regret it are doing tiny toy apps. It is far and away the single worst architectural decision we've ever made.

So what do you recommend? Serious question :) Webapi? WCF always struck me as being too complex with the whole XML service configuration crap.

Mr Shiny Pants
Nov 12, 2012
Anyone else ever have a "How deep does the rabbit hole go?" type of thing?

Let me expand a bit:

I am working on a small application that hosts a webserver, the webserver is based on HTTP listener and after a lot of work I got it working how I want it.
The webserver is used for communicating between applications using JSON and acts as a GUI for the user. The JSON is serialized and deserialized correctly and the pages are being served like they should.

I am using basic authentication for every connection and so the password is being sent over the wire in Base64 encoded strings that are pretty easy to decipher if you know what it should look like. So my thinking in the beginning was
"great, basic auth is pretty simple and very secure once I wrap the the connection in a TLS connection".

Here's where things get interesting real quick.

Hurdle one:
For certificate creation I use the BouncyCastle libraries and they are awesome, they really are. One problem is that you need to find some good tutorials that guide you in how to use them. No problem, Google turned up some awesome blog posts and of we go.
After figuring out how they work I can generate self signed certs and they are written to a directory: the private key in PFX file and the public one in the CER file. Great!

Hurdle two:
If you want to use certificates on HTTP.sys in windows you need to register them using netsh. That sucks, I don't want my application to need to run an external command to set the certificate on the port. Another problem: HTTP listener needs the private key file in a PVK format, which is some Microsoft proprietary crappy private key container format. Bummer.

I found some posts on the internet about pvk2pfx that will convert the PFX file to PVK file and that should work. More dependencies on external tools. Crap.

Hurdle three:
After this I decided to take a look at other options. Lo and behold some nice french guy has ported the Mono HTTP listener to .Net that should be compatible to the one I am using ( I tested my app on Linux, it works ).

Downloaded the source code, crap! It needs certmgr or httpcfg or something to load the certificate from a specified directory in the AppData directory. There goes a nice centralized directory holding all the certificates. :(

At this point I was getting pretty annoyed.

Someone on stackoverflow pointed out that the listener expects the certs in a specific format in a specific location and it will just load the certs without the need for certmgr or httpcfg. Good!

Wrong. It also needs the PVK format.

After reading the listener source code I found out that the Mono people have written a class that converts the PVK file to a AsymmetricAlgorithm .Net base class.

So, I ripped out the certificate loading code from the mono listener and in two lines load my private key from a PFX:

code:
 var pfx = new X509Certificate2(pfx_file, "serverPassword");
                key = (AsymmetricAlgorithm) pfx.PrivateKey; 
Thank god for open source .Net code.

So after three days of pulling my hair out I now have a application that will create it's own CA cert, issue an SSL cert, pass it on to the HTTP listener that will listen on 443 using my just created certificate. Without needing conversion utilities or some other netsh commands.

It looked so easy........

Mr Shiny Pants fucked around with this message at 19:49 on Apr 22, 2014

Mr Shiny Pants
Nov 12, 2012
Working with cetificates is a PITA. No wonder computer security is in shambles, it feels like an overly complicated and over engineered mess. :(

Mr Shiny Pants
Nov 12, 2012

GrumpyDoctor posted:

Has anyone gotten Git Extensions to work with VS 2013? I want more features than the built-in git provider has, but my problem is that the Git Extensions installer puts its plugin onto a network drive (because that's where my user profile lives), which breaks Git Extensions. The workaround is to make a local copy of the plug-in, but I don't know how to get VS to see it. It can see the add-in fine, but there's no entry in the source control provider drop-down.

I think you need to make VS2013 aware of the plugin folder. I had the same problem with my user account being redirected to network drive.

You can add a location to VS2013 where it will look for loading plugins.

At least, that's how i remember getting it working. YMMV ofcourse.

Mr Shiny Pants
Nov 12, 2012
Unity3d is pretty cool. It uses C# as a language.

Adbot
ADBOT LOVES YOU

Mr Shiny Pants
Nov 12, 2012
Hi,

I am working on a FUSE like system that mimics a drive in Windows using the Dokan library. See: http://dokan-dev.net/en/ for details.

Now I've got a rudimentary system running using just a folder on my machine that functions as the basis for the drive. If you run the program you get "T:\" drive that looks like regular harddrive but is in effect a directory on disk.

The one thing I am running into is the order of operations that Windows expect when dealing with file operations.

Example: When deleting a file you go into the DeleteFile method of Dokan but instead of deleting it right away you set the flag "DeleteOnClose" to true. In the "CleanUp" method you do the actual deletion of the file or directory. This tripped me up.

Is there any documentation about this? Something that details the steps that Windows expects when doing these operations? I've looked but I can't really find something useful.

Let's say you rename a directory: What are the steps I need to do to handle this the right way? Do I create a new directory with the new name? Copy over the files and then delete the original directory?

  • Locked thread