Getting the base Document from ThisDocument

When developing a document level Add-In in visual studio, you may have a need to pass the current document to another function. This is tricky, because ThisDocument cannot be cast to a document object.

Turns out, ThisDocument inherits DocumentBase, and has a property called InnerObject. This is the Document.

SortedSet wrapper for .net 3.5

Here is a VERY basic SortedSet wrapper for .NET 3.5
The SortedSet is one of the few new features of the .NET Framework 4.0 that I hate to go without. I recently had to drop a Class Library from 4.0 to 3.5, and the SortedSet was the only thing missing. So, I just created my own SortedSet that is build on the SortedList where TValue is a byte,

Here is my implementation – if you need any of the really fancy features, you will need to implement them yourself.

    public class SortedSet<T> : SortedList<T,byte>
    {
        public SortedSet() : base()
        {
        }

        public T Min
        {
            get
            {
                if ((base.Count) >= 1)
                {
                    return base.Keys[0];
                }
                else
                {
                    return default(T);
                }
            }
        }

        public T Max
        {
            get
            {
                if ((base.Count) >= 1)
                {
                    return base.Keys[base.Keys.Count - 1];
                }
                else
                {
                    return default(T);
                }
            }
        }


        public bool Contains(T value)
        {
            return base.ContainsKey(value);
        }

        public void Add(T value)
        {
            base.Add(value, 0);
        }
    }

Dynamics CRM 4.0 Optimized Web Service Generator

Microsoft Dynamics CRM 4.0 is really a beautiful thing – with a few very annoying exceptions, it is a very flexible, easy to use, easy to customize business application development platform. It includes a comprehensive Web Service that allows you to perform pretty much any UI task programmatically.

There is one problem though – the CrmService proxy class can take upwards of 7 seconds just to initialize the class. Before a singe bit is passed from client to server, you have to wait for the .NET runtime to build the ginormous XmlSerializers for the equally ginormous Web service.

Normally Sgen.exe can be used to improve the startup time of Web Services, but for some reason the CRM Service doesn’t always get along with pregenerated XmlSerializers.

The solution: remove all those unused entities! My organization’s current CRM instance has 192 entities, which translates into (at least) 1,616 separate classes in the generated proxy code.
I have built a tool that consumes a CRM 4.0 web service wsdl, and produces a nice packaged .dll (complete with embedded XmlSerializers) with practically all the unnecessary fluff removed. The produced dll fully supports Fetch and the DynamicEntity – just no static types.

On a .net IIS server, creating a new CrmService now takes 0.12 seconds – instead of 6+.

Update: Released! You can get it on Codeplex here:
http://crmservicegenerator.codeplex.com/

Disabling the URL rewriting on a SonicWall SSL-VPN bookmark

The SonicWall SSL-VPN 2000 is an impressive and feature-packed appliance. For the most part, I have no complaints (well, it would be nice if it worked on the iPhone or iPad, but this is a bigger issue…), but recently we ran into a rather annoying problem.

The SSL-VPN allows you to configure “bookmarks” that are links to your internal resources. Bookmarks can be Remote Desktop, FTP, VNC, and (among others) http and https. For intranet sites that support basic authentication, it will even push credentials.

All urls accessed through the vpn are rewritten something like: https://sslvpn/go/http://intranetsite/index.html. All URLs referenced within are rewritten as well. This works great until it doesn’t.

Say your intranet page has a link to google.com. The SSL-VPN will happily proxy all traffic through itself, rewriting the link to https://sslvpn/go/http://www.google.com.
Now say you had a link to some cloud-based application that doesn’t tolerate being proxied, and you have a problem.

As far as I can tell, SonicWall provides no option to disable rewriting for a specific bookmark. If you have purchased the Web Application Firewall addon, I believe you can setup exceptions, but I’m not even so sure about that. So… I had to try to figure it out myself.

Well after experimenting and digging, I found a workaround involving javascript redirection, obscuring strings, and overriding functions. While I typically would post my solution, I fear that SonicWall might consider it a security hole and simply patch things up without providing a viable solution. So, if you are pulling your hair out over your SSL-VPN rewriting all your external links – there is hope! Shoot me a comment / email and I’ll see if I can’t help you out.

UPDATE 10/18/2011

One of the people who requested my workaround found that in his case there was a much simpler solution: If you simply need to create a bookmark to an external website, you can just configure the bookmark on the SSL-VPN as an “external website”. My workaround is for the case where you need the SSL-VPN to proxy an internal page, but that page has a link (or redirect) to an external page that gets mangled.

Thanks!
-Jason