Note that there are some explanatory texts on larger screens.

plurals
  1. POEndpointNotFound Exception - Dynamics CRM 2011
    primarykey
    data
    text
    <p>When calling the <code>Execute</code> method on a <code>Dynamics CRM 2011 service</code>, passing an ImportSolutionRequest object as a parameter, the following EndpointNotFound exception is thrown:</p> <pre><code>There was no endpoint listening at http://Server.com:5555/Organization/XRMServices/2011/Organization.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. </code></pre> <p>The InnerException is a <code>System.Net.WebException</code>:</p> <pre><code>{"The remote server returned an error: (404) Not Found."} </code></pre> <p>The following code is used to import a solution into a Dynamics CRM 2011 Organization:</p> <pre><code> public override bool Execute() { try { Log.LogMessage(Properties.Resources.importSolutionStarted); CustomNameSpace.Entities.Solution solution = new CustomNameSpace.Entities.Solution(new XrmConnection(DiscoveryServer, Port, Scheme, Organization, Domain, UserName, Password).Connection); solution.ImportSolution(SolutionFilePath); Log.LogMessage(Properties.Resources.importSolutionCompleted); return true; } catch (ApplicationException exception) { Log.LogMessage(exception.Message); return false; } } </code></pre> <p>Here is the Solution Class:</p> <pre><code>public partial class Solution { public Solution(CrmConnection crmConnection) { CrmConnection = crmConnection; ProxyUri = new Uri(String.Format(CultureInfo.CurrentCulture, "{0}/XrmServices/2011/Organization.svc", CrmConnection.ServiceUri)); } private Uri _proxyUri; public Uri ProxyUri { get { return _proxyUri; } set { _proxyUri = value; } } private CrmConnection _crmConnection; public CrmConnection CrmConnection { get { return _crmConnection; } set { _crmConnection = value; } } private IOrganizationService _crmService; public IOrganizationService CrmService { get { return _crmService; } set { _crmService = value; } } private OrganizationServiceProxy _crmProxy; public OrganizationServiceProxy CrmProxy { get { return _crmProxy; } set { _crmProxy = value; } } public Publisher CreatePublisher(string uniqueName, string friendlyName, Uri supportingWebsiteUrl, string customizationPrefix, string eMailAddress, string description) { try { Publisher crmSdkPublisher = new Publisher(); using (CrmProxy = new OrganizationServiceProxy(ProxyUri, CrmConnection.HomeRealmUri, CrmConnection.ClientCredentials, CrmConnection.DeviceCredentials)) { CrmProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior()); CrmProxy.Timeout = new TimeSpan(0, 10, 0); CrmService = (IOrganizationService)CrmProxy; if (supportingWebsiteUrl != null) { crmSdkPublisher = new Publisher { UniqueName = uniqueName, FriendlyName = friendlyName, SupportingWebsiteUrl = supportingWebsiteUrl.AbsoluteUri, CustomizationPrefix = customizationPrefix, EMailAddress = eMailAddress, Description = description }; QueryExpression queryPublisher = new QueryExpression { EntityName = Publisher.EntityLogicalName, ColumnSet = new ColumnSet("publisherid", "customizationprefix"), Criteria = new FilterExpression() }; queryPublisher.Criteria.AddCondition("uniquename", ConditionOperator.Equal, crmSdkPublisher.UniqueName); EntityCollection queryPublisherResults; queryPublisherResults = CrmService.RetrieveMultiple(queryPublisher); Publisher SDKPublisherResults = null; if (queryPublisherResults.Entities.Count &gt; 0) { SDKPublisherResults = (Publisher)queryPublisherResults.Entities[0]; crmSdkPublisher.Id = (Guid)SDKPublisherResults.PublisherId; crmSdkPublisher.CustomizationPrefix = SDKPublisherResults.CustomizationPrefix; } if (SDKPublisherResults == null) { crmSdkPublisher.Id = CrmService.Create(crmSdkPublisher); } } } return crmSdkPublisher; } catch (FaultException&lt;OrganizationServiceFault&gt;) { throw; } } public Publisher RetrieveDefaultPublisher(string organizationName) { try { string DefaultPublisherPrefix = "DefaultPublisher"; Publisher DefaultPublisher = RetrievePublisherByName(DefaultPublisherPrefix, organizationName); return DefaultPublisher; } catch (FaultException&lt;OrganizationServiceFault&gt;) { throw; } } public Publisher RetrievePublisherByName(string defaultPublisherPrefix, string organizationName) { Publisher DefaultPublisher = new Publisher(); using (CrmProxy = new OrganizationServiceProxy(ProxyUri, CrmConnection.HomeRealmUri, CrmConnection.ClientCredentials, CrmConnection.DeviceCredentials)) { CrmProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior()); CrmProxy.Timeout = new TimeSpan(0, 10, 0); CrmService = (IOrganizationService)CrmProxy; QueryExpression queryDefaultPublisher = new QueryExpression { EntityName = Publisher.EntityLogicalName, ColumnSet = new ColumnSet(true), Criteria = new FilterExpression() }; queryDefaultPublisher.Criteria.AddCondition("uniquename", ConditionOperator.Equal, defaultPublisherPrefix + organizationName); Entity publisherEntity = CrmService.RetrieveMultiple(queryDefaultPublisher).Entities[0]; if (publisherEntity != null) { DefaultPublisher = publisherEntity.ToEntity&lt;Publisher&gt;(); } } return DefaultPublisher; } public Solution CreateSolution(string uniqueName, string friendlyName, Guid publisherId, string description, string version) { try { using (CrmProxy = new OrganizationServiceProxy(ProxyUri, CrmConnection.HomeRealmUri, CrmConnection.ClientCredentials, CrmConnection.DeviceCredentials)) { CrmProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior()); CrmProxy.Timeout = new TimeSpan(0, 10, 0); CrmService = (IOrganizationService)CrmProxy; Solution solution = new Solution { UniqueName = uniqueName, FriendlyName = friendlyName, PublisherId = new EntityReference(Publisher.EntityLogicalName, publisherId), Description = description, Version = version }; QueryExpression querySampleSolution = new QueryExpression { EntityName = Solution.EntityLogicalName, ColumnSet = new ColumnSet(), Criteria = new FilterExpression() }; querySampleSolution.Criteria.AddCondition("uniquename", ConditionOperator.Equal, solution.UniqueName); EntityCollection querySampleSolutionResults = CrmService.RetrieveMultiple(querySampleSolution); Solution SampleSolutionResults = null; if (querySampleSolutionResults.Entities.Count &gt; 0) { SampleSolutionResults = (Solution)querySampleSolutionResults.Entities[0]; solution.Id = (Guid)SampleSolutionResults.SolutionId; } if (SampleSolutionResults == null) { solution.Id = CrmService.Create(solution); } return solution; } } catch (FaultException&lt;OrganizationServiceFault&gt;) { throw; } } public Solution RetrieveSolution(string uniqueName) { try { Solution solution = new Solution(); using (CrmProxy = new OrganizationServiceProxy(ProxyUri, CrmConnection.HomeRealmUri, CrmConnection.ClientCredentials, CrmConnection.DeviceCredentials)) { CrmProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior()); CrmProxy.Timeout = new TimeSpan(0, 10, 0); CrmService = (IOrganizationService)CrmProxy; QueryExpression querySampleSolution = new QueryExpression { EntityName = Solution.EntityLogicalName, ColumnSet = new ColumnSet(true), Criteria = new FilterExpression() }; querySampleSolution.Criteria.AddCondition("uniquename", ConditionOperator.Equal, uniqueName); EntityCollection entityCollection = CrmService.RetrieveMultiple(querySampleSolution); if (entityCollection != null &amp;&amp; entityCollection.Entities.Count &gt; 0) { Entity solutionEntity = entityCollection.Entities[0]; if (solutionEntity != null) { solution = solutionEntity.ToEntity&lt;Solution&gt;(); } } else { querySampleSolution.Criteria = new FilterExpression(); querySampleSolution.Criteria.AddCondition("friendlyname", ConditionOperator.Equal, uniqueName); entityCollection = CrmService.RetrieveMultiple(querySampleSolution); if (entityCollection != null &amp;&amp; entityCollection.Entities.Count &gt; 0) { Entity solutionEntity = entityCollection.Entities[0]; if (solutionEntity != null) { solution = solutionEntity.ToEntity&lt;Solution&gt;(); } } } } return solution; } catch (FaultException&lt;OrganizationServiceFault&gt;) { throw; } } public void DeleteSolution(Entity solution) { try { using (CrmProxy = new OrganizationServiceProxy(ProxyUri, CrmConnection.HomeRealmUri, CrmConnection.ClientCredentials, CrmConnection.DeviceCredentials)) { CrmProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior()); CrmProxy.Timeout = new TimeSpan(0, 10, 0); CrmService = (IOrganizationService)CrmProxy; if (solution != null) { CrmService.Delete(Solution.EntityLogicalName, solution.Id); } } } catch (FaultException&lt;OrganizationServiceFault&gt;) { throw; } } public void DeleteSolution(string solutionUniqueName) { try { using (CrmProxy = new OrganizationServiceProxy(ProxyUri, CrmConnection.HomeRealmUri, CrmConnection.ClientCredentials, CrmConnection.DeviceCredentials)) { CrmProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior()); CrmProxy.Timeout = new TimeSpan(0, 10, 0); CrmService = (IOrganizationService)CrmProxy; CrmService.Delete(Solution.EntityLogicalName, GetSolutionIdByUniqueName(solutionUniqueName)); } } catch (FaultException&lt;OrganizationServiceFault&gt;) { throw; } } public void ImportSolution(string solutionFilePath) { try { byte[] fileBytes = File.ReadAllBytes(solutionFilePath); ImportSolutionRequest importSolutionRequest = new ImportSolutionRequest() { CustomizationFile = fileBytes }; using (CrmProxy = new OrganizationServiceProxy(ProxyUri, CrmConnection.HomeRealmUri, CrmConnection.ClientCredentials, CrmConnection.DeviceCredentials)) { CrmProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior()); CrmProxy.Timeout = new TimeSpan(0, 10, 0); CrmService = (IOrganizationService)CrmProxy; CrmService.Execute(importSolutionRequest); } } catch (FaultException&lt;OrganizationServiceFault&gt;) { throw; } } public string ExportSolution(string outputDir, string solutionUniqueName, bool managed) { try { if (!string.IsNullOrEmpty(outputDir) &amp;&amp; !outputDir.EndsWith(@"\", false, CultureInfo.CurrentCulture)) { outputDir += @"\"; } string ManagedStatus; if (managed) { ManagedStatus = "Managed"; } else { ManagedStatus = "UnManaged"; } ExportSolutionRequest exportSolutionRequest = new ExportSolutionRequest(); exportSolutionRequest.Managed = managed; exportSolutionRequest.SolutionName = solutionUniqueName; ExportSolutionResponse exportSolutionResponse; using (CrmProxy = new OrganizationServiceProxy(ProxyUri, CrmConnection.HomeRealmUri, CrmConnection.ClientCredentials, CrmConnection.DeviceCredentials)) { CrmProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior()); CrmProxy.Timeout = new TimeSpan(0, 10, 0); CrmService = (IOrganizationService)CrmProxy; exportSolutionResponse = (ExportSolutionResponse)CrmService.Execute(exportSolutionRequest); } byte[] exportXml = exportSolutionResponse.ExportSolutionFile; string filename = solutionUniqueName + "_" + ManagedStatus + ".zip"; File.WriteAllBytes(outputDir + filename, exportXml); return filename; } catch (FaultException&lt;OrganizationServiceFault&gt;) { throw; } } public void RollbackSolution(string uniqueName, string solutionFullPath) { try { DeleteSolution(uniqueName); ImportSolution(solutionFullPath); using (CrmProxy = new OrganizationServiceProxy(ProxyUri, CrmConnection.HomeRealmUri, CrmConnection.ClientCredentials, CrmConnection.DeviceCredentials)) { CrmProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior()); CrmProxy.Timeout = new TimeSpan(0, 10, 0); CrmService = (IOrganizationService)CrmProxy; CrmService.Execute(new PublishAllXmlRequest()); } } catch (FaultException&lt;OrganizationServiceFault&gt;) { throw; } } public Collection&lt;Solution&gt; RetrieveAllSolutions() { try { Collection&lt;Solution&gt; solutions = new Collection&lt;Solution&gt;(); using (CrmProxy = new OrganizationServiceProxy(ProxyUri, CrmConnection.HomeRealmUri, CrmConnection.ClientCredentials, CrmConnection.DeviceCredentials)) { CrmProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior()); CrmProxy.Timeout = new TimeSpan(0, 10, 0); CrmService = (IOrganizationService)CrmProxy; OrganizationServiceContext ServerContext = new OrganizationServiceContext(CrmService); var items = from item in ServerContext.CreateQuery&lt;Solution&gt;() orderby item.Version ascending where item.IsVisible == true select item; foreach (var item in items) { solutions.Add(item); } } return solutions; } catch (FaultException&lt;OrganizationServiceFault&gt;) { throw; } } public Guid GetSolutionIdByUniqueName(string uniqueName) { try { Guid solutionQuery; using (CrmProxy = new OrganizationServiceProxy(ProxyUri, CrmConnection.HomeRealmUri, CrmConnection.ClientCredentials, CrmConnection.DeviceCredentials)) { CrmProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior()); CrmProxy.Timeout = new TimeSpan(0, 10, 0); CrmService = (IOrganizationService)CrmProxy; OrganizationServiceContext ServerContext = new OrganizationServiceContext(CrmService); solutionQuery = (from item in ServerContext.CreateQuery&lt;Solution&gt;() where item.UniqueName == uniqueName select item.SolutionId.Value).Single&lt;Guid&gt;(); } return solutionQuery; } catch (FaultException&lt;OrganizationServiceFault&gt;) { throw; } } public AddSolutionComponentResponse AddComponentToSolution(componenttype solutionComponentType, Guid componentId, string solutionUniqueName) { try { AddSolutionComponentRequest addSolutionComponentRequest = new AddSolutionComponentRequest() { ComponentType = (int)solutionComponentType, ComponentId = componentId, SolutionUniqueName = solutionUniqueName }; using (CrmProxy = new OrganizationServiceProxy(ProxyUri, CrmConnection.HomeRealmUri, CrmConnection.ClientCredentials, CrmConnection.DeviceCredentials)) { CrmProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior()); CrmProxy.Timeout = new TimeSpan(0, 10, 0); CrmService = (IOrganizationService)CrmProxy; return (AddSolutionComponentResponse)CrmService.Execute(addSolutionComponentRequest); } } catch (FaultException&lt;OrganizationServiceFault&gt;) { throw; } } public void PublishCustomizations() { try { using (CrmProxy = new OrganizationServiceProxy(ProxyUri, CrmConnection.HomeRealmUri, CrmConnection.ClientCredentials, CrmConnection.DeviceCredentials)) { CrmProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior()); CrmProxy.Timeout = new TimeSpan(0, 10, 0); CrmService = (IOrganizationService)CrmProxy; CrmService.Execute(new PublishAllXmlRequest()); } } catch (ApplicationException) { throw; } } } </code></pre> <p>The Solution class makes use of a CrmConnection class as follows:</p> <pre><code>public class XrmConnection { public XrmConnection() { } public XrmConnection(string discoveryServer, string port, string scheme, string organization, string domain, string userName, string password) { DiscoveryServer = discoveryServer; Port = port; Scheme = scheme; Domain = domain; UserName = userName; Password = password; Organization = organization; InstantiateOrganization(); InstantiateConnection(); } public string DiscoveryServer { get; set; } public string Port { get; set; } public string Scheme { get; set; } public string Organization { get; set; } public string Domain { get; set; } public string UserName { get; set; } public string Password { get; set; } [CLSCompliant(false)] public CrmConnection Connection { get; set; } private Uri discoveryServiceUri { get; set; } private OrganizationDetailCollection Orgs { get; set; } private OrganizationDetail Org { get; set; } private RetrieveOrganizationsRequest OrgRequest { get; set; } private RetrieveOrganizationsResponse OrgResponse { get; set; } private OrganizationDetail orgDetail { get; set; } private void InstantiateOrganization() { ClientCredentials clientCredentials = new ClientCredentials(); if (!string.IsNullOrEmpty(Domain)) { clientCredentials.Windows.ClientCredential.Domain = Domain; } if (!string.IsNullOrEmpty(UserName)) { clientCredentials.Windows.ClientCredential.UserName = UserName; } if (!string.IsNullOrEmpty(Password)) { clientCredentials.Windows.ClientCredential.Password = Password; } if (string.IsNullOrEmpty(UserName)) { clientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials; } if (!string.IsNullOrEmpty(Port)) { discoveryServiceUri = new Uri(String.Format(CultureInfo.CurrentCulture, "{0}://{1}:{2}/XRMServices/2011/Discovery.svc", Scheme, DiscoveryServer, Port)); } else { discoveryServiceUri = new Uri(String.Format(CultureInfo.CurrentCulture, "{0}://{1}/XRMServices/2011/Discovery.svc", Scheme, DiscoveryServer)); } using (DiscoveryServiceProxy ServiceProxy = new DiscoveryServiceProxy(discoveryServiceUri, null, clientCredentials, clientCredentials)) { Orgs = DiscoverOrganizations(ServiceProxy); Org = FindOrganization(Orgs); Organization = Org.UniqueName; } } private OrganizationDetailCollection DiscoverOrganizations(IDiscoveryService service) { try { OrgRequest = new RetrieveOrganizationsRequest(); OrgResponse = (RetrieveOrganizationsResponse)service.Execute(OrgRequest); return OrgResponse.Details; } catch (FaultException&lt;OrganizationServiceFault&gt;) { throw; } } private OrganizationDetail FindOrganization(OrganizationDetailCollection orgDetails) { try { orgDetail = null; foreach (OrganizationDetail detail in orgDetails) { if (String.Compare(detail.UniqueName, Organization, CultureInfo.CurrentCulture, CompareOptions.None) == 0) { orgDetail = detail; break; } if (String.Compare(detail.FriendlyName, Organization, CultureInfo.CurrentCulture, CompareOptions.None) == 0) { orgDetail = detail; break; } } return orgDetail; } catch (FaultException&lt;OrganizationServiceFault&gt;) { throw; } } private void InstantiateConnection() { Connection = new CrmConnection(); string connectionString = string.Format(CultureInfo.CurrentCulture, "Url={0}://{1}/{2}", Scheme, DiscoveryServer, Organization); if (!string.IsNullOrEmpty(Port)) { connectionString = string.Format(CultureInfo.CurrentCulture, "Url={0}://{1}:{2}/{3}", Scheme, DiscoveryServer, Port, Organization); } if (!string.IsNullOrEmpty(Domain)) { connectionString = string.Format(CultureInfo.CurrentCulture, "{0}; Domain={1}", connectionString, Domain); } if (!string.IsNullOrEmpty(UserName)) { connectionString = string.Format(CultureInfo.CurrentCulture, "{0}; Username={1}", connectionString, UserName); } if (!string.IsNullOrEmpty(Password)) { connectionString = string.Format(CultureInfo.CurrentCulture, "{0}; Password={1}", connectionString, Password); } Connection = CrmConnection.Parse(connectionString); if (string.IsNullOrEmpty(UserName)) { Connection.ClientCredentials = new ClientCredentials(); Connection.ClientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials; } Connection.DeviceCredentials = Connection.ClientCredentials; } } </code></pre> <p>I am suspecting that this may be a DNS or other network issue. Can anyone help?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload