Thursday, September 25, 2008

WCF service Reference metadata

I was trying earlier today to connect to a WCF service that I had created months ago, and when I created the client, I actually had to create the service reference by hand (this was before VS 2008 had come out).

Today I tried to add the reference directly, and I got the following error message:

Metadata contains a reference that cannot be resolved

which confused me, but the solution turned out to be very easy to fix. Look inside the app.config for your WCF service, and find the <serviceBehaviors> section. Inside there, simply add the node:
<serviceMetadata />

additionally, you need to add another endpoint to your service that obeys the IMetadataExchange contract. This endpoint only needs to look like:

<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />

and I was able to reference my service with no issues.

Labels: ,

Monday, September 15, 2008

Open Source DB search

We recently join a larger company that balked at the fact that our product uses MSSql and wanted us to use a database option that was either free, or didn't cost so much.

We use our databse not only for normal inserts/update/deletes/selects, but we also heavily use SQL replication to mobile computers (using web merge replication). This means that we use multi-master (sort of) asynchronous replication. I've been looking at several other options out there, and can't find anything that fits this bill. MySQL only allows master-slave replication, and the clients need to be able to update the database (often in a disconnected state), so this is out. PostGreSQL looks great, but slony doesn't suggest using itself for replication if you have more than a dozen databases being replicated (we plan on having around 200), and mammoth only supports master/slave. Bucardo looks like the only option that can handle asynchronous multi-master, but it only works on linux boxes, and while I'm okay with making our server a linux box, we are a .Net shop and all of our clients are windows users.

It's looking like we'll move to PostGreSQL on the server, keep SQL CE on the clients, and just create new web services to do all of our replication in house, instead of letting MSSql do it automatically for us. Basically we're talking a couple of months to make our program do again what it already does well.

Labels: , , , ,

Saturday, September 13, 2008

SMTP relay server

I've just had to make an SMTP relay server for a windows 2008 server box, and it wasn't as straight forward as i thought it would be.

First of all, in the Server Manager you have to add a 'feature' and add the SMTP functionality. Second of all, you probably want to add an exception to your firewall for SMTP (usually port 25). Lastly, however, and this is the annoying part, you have to install the IIS 6.0 manager, if you havent done it already. Basically, you use this tool to enable SMTP, and configure it's users in the same way that you would have with windows 2003 server.

Not sure why it's configuration wasn't included with IIS 7, but that took a little work for me to find.

Labels: , ,

Wednesday, September 10, 2008

Using the Wiimote as a mouse with C#

My wife and i recently got rid of our cable subscription, and just hooked up our desktop to our TV instead. Mostly works well for us, but don't really like our setup with the keyboard and mouse. We bought a wireless package, but apparently the max range is 3 feet, and our couch is at least twice that away from the TV. So I've been looking into turning my Wiimote into a mouse device using C#.

Using the WiimoteLib library from Brian Peek you can get total access to the wiimote and it's movements.

I tried using his example of a wiimote mousebut the accelerometer is too sensitive, and it was really difficult to move the mouse to small icons and click them.

Another website decided just to use the absolute X and Y values (IRState.RawMidpoint) instead, which works well for the most part, but the code needed a bit more tweaking to be usable. Some of the things that I modified:

  • ability to adapt dynamically depending on the screen resolution

  • inverted the x axis

  • added a battery life reader.- I additionally added a feature that the mouse won't move unless the 'B' button is held down. This makes it more like the gyroscope mouse, which is what I've used in the past.

  • Additionally, i upgraded the project to VS 2008, and the latest WiimoteLib library.


I've put the project here if you want to try it out.

The main issue i have with it is that the mouse X value can move off the screen to the right, as if the systeminformation.primaryscreen.width value is incorrect, and makes the value larger than it actually is. I've included an offset to fix this, but it's just odd, considering that the Y value is dead on.

Labels: , , ,

Monday, September 8, 2008

Arg!

Okay, scratch my last idea. There is no way to access an isolated storage file via a URI, which is what I was kinda counting on. Not sure where to go from here. Everything i find, most people end up just suggesting 'oh, just covert the bytes into a string, and read the string values themselves', but of course, i can't do that if I'm trying to read a .pdf file. I'll still look into this, but it might not be doable without having to write the file temporarily to the computer out in the open. And since they would need the password to open the file anyways, I would simply have to depend on putting the file in an 'odd' place that the user wouldn't look for it, and that is pretty unacceptable security.

Update:
I started looking into Apose.pdf.kit, which worked great with the trial. The software allows you to take a .pdf file, load it into a memorystream, and decode all the pages in the .pdf file into an array of system.drawing.bitmaps. The only issue (for me) was that it takes about 2 seconds to decode each page, so decoding them all up front isn't really practical, you need to decode each page on demand.

The only issue with the software was that it costs around $1700 for the single developer, royalty free license. Jeez.

In the end, we decided to just export the files with adboe writer into images, and just make a tool to view the images as if it was a pdf. I had to write a hook program to disable the printscreen button, but after that, the tool basically does what I want. Still feels like cheating though.

Labels: , , , ,

Friday, September 5, 2008

Viewing a document in memory with WPF

I have to create a tool that displays documents to a user with a memorystream. I decided to try this with wpf, but i was having a lot of trouble with it.

This site was giving me the idea on how to view xps documents through a memorystream, but I was getting a corrupted file error on Package.Open when i tried to read a .doc or .pdf file. The files that I'll be needing to read are mostly .pdf files.

I don't want to make the file available to the users, which is why i'm not just quickly writing the data from it's bytes to a an actual file, and just reading that. I've ended up just deciding to make a compromise with that, and use isolated storage to write the file to, and purge it when the app is done. Feels like a cheat, but I'm not getting many better results.

I integrated a webbrowser with my WPF code using windowsformsintegration:

<WindowsFormsHost>
<winfrm:WebBrowser x:Name="wbBrow"></winfrm:WebBrowser>
</WindowsFormsHost>

I tried playing with the 'documentstream' option on the webbrowser control, but that doesn't work for .pdf files, it just shows gibberish. I also tried using adobe's own COM control, but there is only a "LoadFile" option, which doesn't give me any extra help.

One of the real annoying things about this project is that the pdf file is password protected, and i have no idea how avoid getting the user to type in the password by doing it programmatically.

Labels: , , , , , ,

Thursday, September 4, 2008

Copy data from a select in a WPF Listview

Simple little thing that was useful, i needed to copy the data from a row in a listview to the clipboard. all i needed to do was add the following to my listview:

<ListView.CommandBindings>
<CommandBinding Command="Copy" CanExecute="CommandBinding_CanExecute" Executed="CommandBinding_Executed"/>
</ListView.CommandBindings>

and then create the methods for the CanExecute and Executed in the code-behind. For my CanExecute, i just checked if a row was selected, and for the Executed, i took the selected row, and casted it as the object that i expected, and put the data i wanted from the object in the clipboard

Clipboard.SetText(thePrj.ProjectGUID.ToString)

Very easy!

Labels: , , ,

Tuesday, September 2, 2008

Exporting a web report as a word doc

I've been working on a project where a user can naviagate to a web page, and choose to download the latest information on a project as a word document. This information can contain grids, attachments, all sorts of things. I decided to take the easy/quick way of doing this, and just write out HTML to the actual web page. On the response object, i would simply set:


HttpContext.Current.Response.Clear()
HttpContext.Current.Response.Charset = ""
HttpContext.Current.Response.ContentType = "application/msword"
HttpContext.Current.Response.AddHeader("Content-Disposition", "inlinefilename=" + strFileName)

i would then write out the content as HTML, where strHTMLContent is a stringbuilder. Something like:

strHTMLContent.Append("<br/>")
strHTMLContent.Append("<table align="'Center'" width="'100%'">")
strHTMLContent.AppendLine("<tr><th>Attachments:</th></tr>")
strHTMLContent.AppendLine("<tr><td>")

'blah blah blah, and then i would finish it by:

HttpContext.Current.Response.Write(strHTMLContent)
HttpContext.Current.Response.End()
HttpContext.Current.Response.Flush()

This works fine for the most part, but the attachments make it a bit annoying. For images, i just use a reference to "<img src='viewattachment.aspx?...",, where i created a secondary web page called "viewattachment" that can display my attachments based on a primary key value.

When the word doc gets saved, since it has the .doc extension, it's opened by Word, but it isn't an actual word file, regardless of the ContentType value I entered in at the top. This means that opening the word file calls the link to the viewattachment.aspx web page, which isn't really acceptable if the client opening the word doc has no internet connection. If you choose to 'save as' for the document, it will show that it sees it as an .html file. If you choose to save it as a word document, then that embeds the image.

An annoying extra step, but probably what I have to deal with by taking the easy way out and avoiding word COM objects.

The last point was that using the "<iframe src=''" string to show attachments doesn't work at all. It just doesn't show up in the word document, HTML version or DOC version. Some of our attachments are html documents, and i was hoping to display them that way, but it looks like i'll have to open each document one-by-one and write out their text.

Labels: , , ,