Friday, December 21, 2012

TFS 2010, VS 2010: No service host is available for the request; Service Unavailable – HTTP Error 503. The service is unavailable

TFS 2010 configuration issues: 

1. Service Unavailable – HTTP Error 503. The service is unavailable.

2. No service host is available for the request

If you are experiencing one of these errors while trying to configure TFS 2010, please see the solutions which worked for me. 

1. 503 error. 

- Check the application pools (You should have two created on the installation of TFS 2010) and make sure they are running. In my case the application pool was being stopped. The Identity I used for this was the same as the local Admin account I created on the Windows 2008 R2 server where TFS 2010 has been installed but for some unknown reason, as soon as I try to access the TFS from Visual studio or browser, the application pool goes into Stopped status. I changed the Identity to Local Service and then the Application pool wasn't being stopped but then I was getting the second error, described below when trying to access it from VS 2010 or browser. 

- I don't know if this is an issue but I altered between changing the .Net framework version to be used by the App pool from 2.0 to 4.0. I read many articles where some suggested using 2.0 while others suggested using 4.0. MSDN suggests using 4.0. Finally I ended up using 4.0 with the Identity as suggested below, then it worked for me.

2. No service host is available for the request. 

- In my case, I created a local admin on the Windows 2008 R2 server where the TFS 2010 was installed and tried to use the same as Identity for my application pools but for some unknown reason the application goes into stopped mode as soon as I tried to connect to TFS via VS 2010 or browser. Finally changing the account in TFS console to Network service and using the same for the App pool's Identity fixed it for me. 
So if none of the solutions online are working for you. Go ahead and browse the TFS Admin console, select the Application Tier, on the right hand side of Application Tier summary, click on Change Account and select the drop down list option for Network service. Restart your App pool (IIS if you need to). 


Hope this helps! 

Thursday, December 20, 2012

Team Foundation Server 2010 - Working folder is already in use

Issue: Working folder is already in use

Resolution:
1. Open up command prompt from Start >> Programs >> Visual Studio 2010 Tools.
2. Run the following commands:

- to check the existing work-spaces on your local machine:
   tf workspaces /server:http://:8080 /computer:-client
    tf workspaces /computer: /owner:* /format:detailed

- to delete those work-spaces
    tf workspace /delete /server:http://:8080 ;\

Try the delete for each of the workspace or for whichever workspace you don't need. If you deleted all, you can start afresh by creating new workspaces. 

Sunday, December 2, 2012

Consuming Oracle CRM OnDemand web services from .Net (C#)

Oracle CRM web services' documentation is not straight forward for implementation, at least I felt so. I had to figure it out the hard way but finally I was able to query and update. So here it is for anyone else embarking on the same path. 

1. Download the custom WSDL and NOT "Schema" after logging to CRM on demand website from the Admin > web services administration link. [Select Web Services 2.0 from the select services drop down box.]. Save it to a location on your drive and this is what you will reference from your "Add web reference" dialog box.

Note: This wsdl file will be huge (in tens of megs). 

2. In your project, select "Add web reference", type the path of the wsdl file on your drive. e.g. c:\oraclecrmsvc\contact.wsdl

You can find online examples of how to sign-in and make web service requests from this page - http://www.oracle.com/technetwork/indexes/samplecode/crmod-sample-522104.html. (R17Advsample1.zip - This has lot of examples about query, update, delete, etc., also to sign in).
 NOTE: Without signing in via the web service request, you cannot make request to query, update, delete or anything for that matter. 

Code: 


using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using XeroxOracleCrm.Svc.ContactSvc;
using System.Net;
using System.Data.SqlClient;
using System.Configuration;
using System.Text;
using System.Reflection; 
 
namespace XeroxOracleCrm.Svc
{
    [WebService(Namespace = "http://abc.Svc/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class XeroxOracleCrmBridgeService : System.Web.Services.WebService
    {
        public string server = ConfigurationManager.AppSettings["CrmUrl"]; 
        public string username;
        public string password;
        public string sessionId;
        public Cookie cookie;
 
        [WebMethod]
        public string Contacts(string customerId)
        {
            if (!string.IsNullOrEmpty(customerId))
            { 
                customerId = customerId.Trim();
                if (string.IsNullOrEmpty(customerId))
                {
                    return "Invalid Customer ID"; 
                }
            }
 
            string errorObtainingSession = Establish();
            if (!string.IsNullOrEmpty(errorObtainingSession))
            {
                return "Error obtaining Oracle CRM On Demand's session. Message: " + errorObtainingSession; 
            }
 
            string response = GetContacts(customerId); 
 
            Destroy();
 
            return response; 
        }
 

        #region Private Methods
        //You have to instantiate the properties in the request, which you want in the
        // response.
        private string GetContacts(string customerId)
        {
            Contact c = new Contact();
 
            ContactQueryPage_Input cqi = new ContactQueryPage_Input();
 
            ContactQuery cq = new ContactQuery();
            cq.ContactFirstName = new queryType();
            cq.ContactLastName = new queryType(); 
            cq.ContactEmail = new ContactSvc.queryType();
            cq.ContactFullName = new ContactSvc.queryType();
            cq.ContactType = new queryType();
            cq.CustomerId = new queryType(); 
            cq.Id = new ContactSvc.queryType();
            cq.AccountId = new ContactSvc.queryType();
     
            cq.AssistantPhone = new ContactSvc.queryType();
            cq.HomePhone = new ContactSvc.queryType();
            
            cq.CustomText0 = new queryType();
            cq.CustomText1 = new queryType();
            cq.CustomText2 = new queryType();
            cq.CustomText3 = new queryType();
            cq.CustomText4 = new queryType();
            cq.CustomText5 = new queryType();
            cq.CustomText6 = new queryType();
            cq.CustomText7 = new queryType();
            cq.CustomText8 = new queryType(); 
            cq.QualifiedDate = new ContactSvc.queryType();
            cq.OwnerFullName = new ContactSvc.queryType();
            cq.LastCallDate = new ContactSvc.queryType();
            cq.LastActivityDate = new ContactSvc.queryType();
            cq.Gender = new ContactSvc.queryType();
            cq.CreatedDate = new ContactSvc.queryType();
            cq.ModifiedDate = new ContactSvc.queryType();
            cq.CreatedById = new ContactSvc.queryType();
            cq.CreatedByEMailAddr = new ContactSvc.queryType();
 
            cq.ExternalSystemId = new ContactSvc.queryType(); 
            cq.IndexedDate0 = new queryType();  
            cq.IndexedBoolean0 = new queryType();
            cq.IndexedCurrency0 = new queryType();
            cq.IndexedLongText0 = new queryType();
            cq.IndexedNumber0 = new queryType();
            cq.IndexedPick0 = new queryType();
            cq.IndexedPick1 = new queryType();  
            cq.IndexedPick2 = new queryType();
            cq.IndexedPick3 = new queryType();
            cq.IndexedPick4 = new queryType(); 
            cq.IndexedPick5 = new queryType();
            cq.IndexedShortText0 = new queryType(); 
            cq.IndexedShortText1 = new queryType(); 
            
            cq.ContactRole = new ContactSvc.queryType();
 
//You can use whatever query you want. Play with it. 
            cq.searchspec = "([ExternalSystemId] = '" + customerId +"')";
 
            ListOfContactQuery lcq = new ContactSvc.ListOfContactQuery();
            lcq.pagesize = "5";
            lcq.startrownum = "0";
            lcq.recordcountneeded = true;
            lcq.Contact = cq;
 
            cqi.ListOfContact = lcq;
 
            c.Url = GetURL();
            try
            {
                ContactQueryPage_Output co = c.ContactQueryPage(cqi);
                if(co.ListOfContact != null && co.ListOfContact.Contact != null && co.ListOfContact.Contact.Length > 0)
                {
                    ContactData cData = co.ListOfContact.Contact[0];
                    PropertyInfo[] properties = cData.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
                    StringBuilder sbContactData = new StringBuilder(); 
                    foreach (PropertyInfo property in properties)
                    {
                        sbContactData.AppendLine(property.Name + ": " + property.GetValue(cData, null));
                    }
                    return sbContactData.ToString(); 
                }
                return string.Empty; 
            }
            catch (Exception ex)
            {
                return ex.ToString();
            }
        }
  
        private string GetURL()
        {
            if (sessionId == null)
            {
                throw new Exception("No session has been established!");
            }
            
            return server + "/Services/Integration;jsessionid=" + sessionId;
        }
 
        private string GetLogInURL()
        {
            return server + "/Services/Integration?command=login";
        }
 
        private string GetLogOffURL()
        {
            return server + "/Services/Integration?command=logoff";
        }
 
        private string Establish()
        {
            try
            {
                // create a container for an HTTP request
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(GetLogInURL());
 
                // username and password are passed as HTTP headers
                req.Headers.Add("UserName"ConfigurationManager.AppSettings["CrmUserName"]);
                req.Headers.Add("Password"ConfigurationManager.AppSettings["CrmPassword"]);
 
                // cookie container has to be added to request in order to 
                // retrieve the cookie from the response. 
                req.CookieContainer = new CookieContainer();
 
                // make the HTTP call
                HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
                if (resp.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    // store cookie for later...
                    cookie = resp.Cookies["JSESSIONID"];
                    if (cookie == null)
                    {
                        throw new Exception("No JSESSIONID cookie found in log-in response!");
                    }
                    sessionId = cookie.Value;
                }
            }
            catch (Exception ex)
            {
                return ex.Message; 
            }
            return ""; 
        }
 
        private void Destroy()
        {
            // create a container for an HTTP request
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(GetLogOffURL());
 
            // reuse the cookie that was received at Login
            req.CookieContainer = new CookieContainer();
            req.CookieContainer.Add(cookie);
 
            // make the HTTP call
            HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
            if (resp.StatusCode != System.Net.HttpStatusCode.OK)
            {
                throw new Exception("Logging off failed!");
            }
            // forget current session id
            sessionId = null;
        }
 
        #endregion
    }
}


Note: Use fiddler to see the requests and responses. 



Good luck!