Hi,
I need to retreive the picklist items values using MetaData service.
I am not able to connect to the MetaData Service in my production environment which is an IFD deployment.
It gives me an "401 : UnAuthorised Error." . The same code works well in my development environment which is a VPC environment.
Pls find code below for the same.
Also when I look at the log file the error oroiginates from the line
"RetrieveAttributeResponse amRes = (RetrieveAttributeResponse)service.Execute(attribReq);"
The metadata service url created is fine and it returns the meta methods when pasted on a web browser.
public static MetadataService GetMetaDataService()
{
MetadataService service = new MetadataService();
try{
string organization = "PROD"; //ConfigurationManager.AppSettings["OrgName"].ToString();
string server = "PRODUCTION";//ConfigurationManager.AppSettings["ServerName"].ToString();
string domain = "HOSTING";//ConfigurationManager.AppSettings["CRMDomain"].ToString();
string username = "Administrator";//ConfigurationManager.AppSettings["CRMUserName"].ToString();
string password = "XXXXXX";//ConfigurationManager.AppSettings["CRMPassword"].ToString();
string VDBAuthenticationType = "SPLA";//ConfigurationManager.AppSettings["AuthenticationType"].ToString();
service.Credentials = new System.Net.NetworkCredential(username, password,domain);
string Server = "PRODUCTION"; //ConfigurationManager.AppSettings["ServerName"].ToString();
string Port = "80";//ConfigurationManager.AppSettings["PortNumber"].ToString();
service.CrmAuthenticationTokenValue = new MetaSdk.CrmAuthenticationToken();
service.CrmAuthenticationTokenValue.OrganizationName = organization;
if (Port != "")
service.Url = string.Format("http://{0}:{1}/mscrmservices/2007/metadataservice.asmx", Server, Port);
else
service.Url = string.Format("http://{0}/mscrmservices/2007/metadataservice.asmx", Server);
}
catch(SoapException ex)
{
ErrorWriter(ex,"Meta Sevice Error");
}
}
Also the code for Retreiving picklist Values is here
public static int GetPickListItemValue(string entityName, string pickListName, string itemLabel)
{
int itemValue = 0;
try
{
MetadataService service = new MetadataService();
service = GetMetaDataService();
RetrieveAttributeRequest attribReq = new RetrieveAttributeRequest();
attribReq.EntityLogicalName = entityName;
attribReq.LogicalName = pickListName;
// Get the attribute metadata for the pickListName attribute.
RetrieveAttributeResponse amRes = (RetrieveAttributeResponse)service.Execute(attribReq);
AttributeMetadata am = amRes.AttributeMetadata;
PicklistAttributeMetadata listData = (PicklistAttributeMetadata)am;
foreach (Option option in listData.Options)
{
foreach (LocLabel label in option.Label.LocLabels)
{
// Show US English value:label pairs
if (label.LanguageCode.Value == 1033)
if (label.Label.Equals(itemLabel))
{
itemValue = option.Value.Value;
}
}
}
}
catch(SoapException ex)
{
ErrorWriter(ex,"Error in Retreiving PickList Values, Metadata Sevice Error");
}
return itemValue;
}
Pls help me out.
I am stuck with this code as it works fine in mu[y VPC but gives "401 error" in the production.
Also I have verified that the logged in user has the righta for Entity, Relationship and Attribute as he is the administarator of CRM.
I have also added </clear> tag in the web.config file but no sucess.
Regards
Susan