Friday, December 26, 2014

Socket.io from IE8 and IE9

My initial implementation of socket.io worked great with Chrome and Firefox; however, notifications were not being sent to Internet Explorer. The error was:

FlashPolicyFileServer received an error event:listen EADDRINUSE

The solution is in this post https://github.com/Automattic/socket.io/issues/1011 and basically, you need to do this on the server:

io.set('flash policy port', 3300);       //override policy port  
io.set('transports', [                     // enable all transports (optional if you want flashsocket)
    'websocket'
  , 'flashsocket'
  , 'htmlfile'
  , 'xhr-polling'
  , 'jsonp-polling'
]);

and this on the client:

var socket = io.connect(socketAddr,{'flash policy port':3300});

Wednesday, September 24, 2014

Missing SSIS toolbox

The other day I couldn't find the toolbox to add a component, so I followed these instructions. Basically a right click is enough, but I'm still learning the ropes:

http://geekswithblogs.net/AskPaula/archive/2013/07/11/153385.aspx

Friday, September 5, 2014

Debugging MDX queries

To put it simple, IT IS NOT POSSIBLE. I came across this tool http://www.sqlbi.com/tools/mdx-studio/ but it didn't help me a lot. What helped me was this article http://blogs.adatis.co.uk/blogs/jeremykashel/archive/2013/06/14/debug-mdx-with-generate.aspx which talks about using the Generate aggregate function to generate "logs".

It helped me find an incorrect sum in an mdx query, so I highly recommend this technique.

Tuesday, September 2, 2014

An MDX alternative to DistinctCount in SSAS

I got started using SSAS and SSIS, and needed to implement a DistinctCount in an MDX query. Eventually (after a few hours) I came up with a solution, and a few days later found the solution here:

http://richardlees.blogspot.mx/2008/10/alternative-to-physical-distinct-count.html

Saturday, May 31, 2014

Logging in WCF

Have you ever wondered how to log messages sent to a WCF service? I had an iPhone app not being able to connect to a method in a WCF service, so I did this to enable logging of requests:

  <diagnostics>
    <messageLogging
         logEntireMessage="true"
         logMalformedMessages="true"
         logMessagesAtServiceLevel="true"
         logMessagesAtTransportLevel="false"
         maxMessagesToLog="3000"
         maxSizeOfMessageToLog="2000"/>
  </diagnostics>
  </system.serviceModel>
<system.diagnostics>
  <sources>
      <source name="System.ServiceModel.MessageLogging">
        <listeners>
                 <add name="messages"
                 type="System.Diagnostics.XmlWriterTraceListener"
                 initializeData="c:\logs\messages.svclog" />
          </listeners>
      </source>
    </sources>

</system.diagnostics>

Then once you have a log file, open it with SvcTraceViewer.exe, the Service Trace Viewer tool from Microsoft.

Saturday, May 17, 2014

Socket.io: Sending logs to a file

It's quite simple to send the console messages from socket.io to a file. I followed this tutorial (http://masashi-k.blogspot.mx/2013/02/logger-for-socketio-save-it-into-redis.html) and the steps are:

1) Install winston
2) Configure the logger output file
3) Link the logger to socket.io using this code:


 var io = require('socket.io').listen(server, {
      logger : logger
    });

Monday, April 14, 2014

Calling JSON WCF Services from .NET 3.5

The short answer is that you need to use the WebClient class. For the lengthy answer, check out this link:

http://www.c-sharpcorner.com/uploadfile/dhananjaycoder/wcf-rest-service-with-josn-data/

Thursday, March 20, 2014

Multiple types were found that match the controller named 'MyController' in the Web API

This is a really dumb error. It happened to me after renaming some projects in the solution, and the way to fix it is deleting the files in the bin directory and rebuilding the code. Thanks stackoverflow!

Monday, March 17, 2014

Invoking the ASP.NET Web API from a client in .NET 3.5

It's actually pretty simple. I followed this post, but basically you just have to do the following.

http://www.thepicketts.org/2012/11/how-to-access-webapi-from-a-net-3-5-client-in-c/

public static object postWebApi(object data, Uri webApiUrl) {
    // Create a WebClient to POST the request
    WebClient client = new WebClient();

    // Set the header so it knows we are sending JSON
    client.Headers[HttpRequestHeader.ContentType] = "application/json";

    // Serialise the data we are sending in to JSON
    string serialisedData = JsonConvert.SerializeObject(data);

    // Make the request
    var response = client.UploadString(webApiUrl, serialisedData);

    // Deserialise the response into a GUID
    return JsonConvert.DeserializeObject(response);
}

Saturday, March 15, 2014

Installing Exchange Server 2007 Prerequisites

I found myself doing this to learn Exchange for a project. Following these steps helped me through the process.

http://www.it-book.co.uk/1922/install-exchange-2007-on-windows-2008-r2

Sunday, March 9, 2014

Exchange 2007 EWS - The connection to the mailbox is unavailable

I've been using EWS and after an Exchange Server reboot, this message appeared when connecting to EWS: "The connection to the mailbox is unavailable".

The first place where I thought I should start was the Services module in the Exchange mailbox. Just make sure the Microsoft Exchange services (specially the Microsoft Exchange Information Store) are up and running. Of course, there maybe several reasons for this error, it turned out that for me this fixed it.

Tuesday, March 4, 2014

The (real) way to delete a contact email in EWS (Exchange Web Services)

I've found several posts on how to delete the email of a contact. Of course, setting it to null doesn't work. This is what worked for me: first, follow the instructions on this blog.

http://blogs.msdn.com/b/emeamsgdev/archive/2012/05/17/ews-managed-api-how-to-remove-email1-email2-email3-from-a-contact.aspx

But first make sure you read these properties when retrieving the contact to be updated. I was not doing that and it took me a couple of hours to figure out.

Tuesday, February 18, 2014

Preventing XSRF attacks in Angular with ASP.NET MVC

This is not an easy problem to solve. First, you need to follow this link to implement the overall solution with tokens:

http://www.asp.net/web-api/overview/security/preventing-cross-site-request-forgery-(csrf)-attacks

The problem comes with Angular and an application that supports login/logout. That's because the Angular router only requests the templates/pages once, which means the token is only downloaded once (subsequent requests will come from cache). In our scenario, a user could access the application with different accounts, which meant that while the browser was opened, only one token existed and this was causing errors (because different users must have different tokens, otherwise this is considered an XSRF attack). Long story short, the solution was to request the token after the user signed in by causing a page refresh.

This is probably not the best solution, but the alternative was to request the token from the controllers, which would require significant changes and pollution in your classes.

Monday, February 17, 2014

Reading resx programmatically and avoid compiling it with the code

Usually I would be against having a Resources.resx file in production code. It would be better to compile it or put the resources in a database. However, if you need to read the contents in a web project, you could do something like this (from http://msdn.microsoft.com/en-us/library/gg418542(v=vs.110).aspx):

string resxFile = HttpContext.Current.Server.MapPath(@"/CarResources.resx");
      List<Automobile> autos = new List<Automobile>();
      SortedList headers = new SortedList();

      using (ResXResourceReader resxReader = new ResXResourceReader(resxFile))
      {
         foreach (DictionaryEntry entry in resxReader) {
            if (((string) entry.Key).StartsWith("EarlyAuto"))
               autos.Add((Automobile) entry.Value); 
            else if (((string) entry.Key).StartsWith("Header")) 
               headers.Add((string) entry.Key, (string) entry.Value);      
         } 
      }

Wednesday, January 29, 2014

Default parameter specifiers are not permitted

This error started appearing in our Cruise Control .NET build. However, we were not getting any errors from Visual Studio in the development environment. We are targeting .NET 3.5, and it turned out some methods were using optional parameters, which do not exist in .NET 3.5. However, Visual Studio is smart enough to be able to compile the code, but csc.exe (which is used by CC.NET) is not. We had to remove the optional parameters and to make sure it didn't happen again, we set the Language Version to C# 3.0 in Project Properties -> Build -> Advanced -> Language Version. Check out this post for more detailed information

http://engineering.thetrainline.com/2013/06/20/using-visual-studio-2010-to-target-net-3-5/