Windows Azure Platform Developer Center > Azure Forums > AppFabric > ServiceBus application run in the cloud crashes
Ask a questionAsk a question
 

AnswerServiceBus application run in the cloud crashes

  • Monday, June 29, 2009 7:01 AMHallgeir Lien Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi.

    I'm attempting to use the Service Bus to create a simple service to import data into a Azure Table. The application is to be run in Azure (that is, the application is to be uploaded to the cloud, one or more clients are to be run outside of the cloud). It consists mainly of a worker role and a web role (though, only the worker role is of interest here, the web role should only view the result). The worker role sets up an endpoint, authenticates with the solution name and password and everything. The client will then connect to this service's endpoint, and sends data to it by calling the "Import" function on the service contract.

    The service runs perfectly when I run the cloud service in the development fabric. It even registers in the ATOM feed in the Service Bus "control panel" on MS's management site, and I can connect using my client.

    The problem comes when I deploy the service application in the cloud. Then the worker (sometimes) runs for a few minutes, then its status is set to "Stopped". While it's running, no service is registered in the ATOM feed. Then sometimes it starts up again, runs for a little while, then stops again. My guess is that an exception of some sort is thrown, and the application crashes. I've attempted to look at the logs, but for some reason, no logs are generated for my worker role, only my web role. So it's quite hard to debug. I'll post the code for my worker's Start() function below:
            ServiceHost host;
    
            public override void Start()
            {
                RoleManager.WriteToLog("Information", "Worker started!");



    //Create the service Uri uri = ServiceBusEnvironment.CreateServiceUri("sb", "(my solution's name)", "importservice"); host = new ServiceHost(typeof(ImportService), uri); ContractDescription contract = ContractDescription.GetContract(typeof(IImportService), typeof(ImportService)); ServiceEndpoint serviceEndpoint = new ServiceEndpoint(contract);
    serviceEndpoint.Address = new EndpointAddress(uri); serviceEndpoint.Binding = new NetTcpRelayBinding(); //Set up authorization TransportClientEndpointBehavior creds = new TransportClientEndpointBehavior(); creds.CredentialType = TransportClientCredentialType.UserNamePassword; creds.Credentials.UserName.UserName = "(my solution name)"; creds.Credentials.UserName.Password = "(my solution's password)"; serviceEndpoint.Behaviors.Add(creds); //Make it public ServiceRegistrySettings settings = new ServiceRegistrySettings(); settings.DiscoveryMode = DiscoveryType.Public; serviceEndpoint.Behaviors.Add(settings); //Set up the listener host.Description.Endpoints.Add(serviceEndpoint); host.Open();

    while (true) { RoleManager.WriteToLog("Information", "Working..."); Thread.Sleep(10000); } }

    Here is my service contract interface and my actual service:
        [ServiceContract(Name="ImportService")]
     public interface IImportService
     {
     [OperationContract]
     void ImportXML(string xmlDoc);
     }
    [ServiceBehavior]
     public class ImportService : IImportService
     {
     public void ImportXML(string xmlDoc)  {
     DataLayer dal = new TablesDataLayer();
     dal.Import(xmlDoc);
    RoleManager.WriteToLog("Information", "Importing XML document...");
     }
     }

    The code in the ImportXML function never gets called, since it crashes before I'm able to call it. So I'm quite sure the problem is somewhere else. Does anyone have any idea of what I can have done wrong here? Or maybe how to get the worker role's logging up and running properly so I can debug this?

    Best regards,
    Hallgeir

Answers

  • Monday, June 29, 2009 12:54 PMBrentDaCodeMonkey Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    I believe I saw that the service bus assembly must be part of your deployment package. However, I can't confirm this yet (its on my plate for this week).

All Replies