Monday, December 26, 2011

Tuesday, October 11, 2011

Simple way to debug Windows Service startup


If you come to situation that you need to debug the startup of your Windows Service here's a simple and dirty (and stupid) method that helps in most situations.
This could be used in situation where your service immediately starts and stops.
Windows Services reports a message like this:

The "serviceName" service on Local Computer started abd then stopped. Some services stop automatically if they are not in use by other services or programs.
Usually, to debug a service you'll need to setup the breakpoint in your code, attach to the process from Visual Studio, and debug upon hitting the breakpoint.
Problem is if your service immediately exits and your don't have time to attach the debugger.
Simple, stupid way to debug it is to... guess what?... add a Thread.Sleep() as the first line in your code.
Sample, service acting as a WCF Host and it's OnStartup() method:


protected override void OnStart(string[] args)
{
   System.Threading.Thread.Sleep(30000);
   myHost= new ServiceHost(typeof(MyService)); //set breakpoint here
   myHost.Open();
}



Now you have enough time to attach the debugger from Visual Studio and you don't have to use Windows Debugger Tools or similar advanced methods.

Tuesday, March 15, 2011

Setting up MMS on Google Nexus One

Here's a short post if you ever come to a problem setting up MMS on Google's Nexus One phone.
As far as I've figured it out, the problem emerges if your operator requires different APN's for Internet connection and MMS service.
To skip all the trouble I had figuring out what's the problem, the bottom line is that you must set APN type for the one that you use for Internet access to "default" and APN type for MMS must be set to "mms". Caps matter.
All the time I've left APN type for the Internet APN empty. Nexus One lets you write anything you want for acces, other Android devices usually let you choose from one of the predefined values. If you left it empty, Internet access will work, but if you define another APN for MMS (there you must enter "mms" as APN type), MMS won't work. When you set APN type of the Internet APN to "default", and left everything else as before, MMS will start working.

Here are the sample settings for my operator (BH Mobile) that work on my Nexus One.

  1. Internet APN
    • Name: BHMobile
    • APN: active.bhmobile.ba
    • Proxy:
    • Port:  
    • Username:  
    • Password:  
    • Server:  
    • MMSC:  
    • MMS Proxy:
    • MMS port:  
    • MCC: 218 (this can be different for your operator, Nexus One usually automatically recognizes it)
    • MNC: 90(this can be different for your operator, Nexus One usually automatically recognizes it)
    • Authentication type: None
    • APN type: default (this was the problem all the time while MMS didn't work, it was not set)
  1. MMS APN
    • Name: BHMobileMMS
    • APN: mms.bhmobile.ba
    • Proxy:
    • Port:  
    • Username:  
    • Password:  
    • Server:  
    • MMSC:  http://mms.bhmobile.ba/cmmsc/post
    • MMS Proxy: 195.222.056.041
    • MMS port:  8080
    • MCC: 218 (this can be different for your operator, Nexus One usually automatically recognizes it)
    • MNC: 90(this can be different for your operator, Nexus One usually automatically recognizes it)
    • Authentication type: None
    • APN type: mms 
What is really weird is that Internet APN setting was causing problems with MMS APN. I assume that it was using the Internet APN when trying to send MMS until I've set the APN type to default. Afterwards, it searched the MMS APN and used the correct one. Just assumption...