Microsoft 开发人员网络 > 论坛主页 > AppFabric > ServiceBus application run in the cloud crashes
提出问题提出问题
 

已答复ServiceBus application run in the cloud crashes

  • 2009年6月29日 7:01Hallgeir Lien 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    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

答案

全部回复