InvalidOperation Exception when calling ServiceConfigurationFactory.CreateConfiguration
-
26 เมษายน 2555 9:56
I have a test client application which is establishing a connection to a CRM2011 environment on a remote server in a different domain. However, when I invoke the code:
DiscoveryServiceURI = GetDiscoveryServiceURI(ServerName)
DiscoveryInfo = ServiceConfigurationFactory.CreateConfiguration(Of IDiscoveryService)(DiscoveryServiceURI)I get the exception below. It looks like I need to provide a usercode/password etc at this point but I can't see any way of doing this. The code works fine if I call a local CRM environment, it only fails if I try to call a CRM environment which requries authentication when establishing the discovery service.
System.InvalidOperationException was unhandled
Message=Metadata contains a reference that cannot be resolved: 'http://xxx.xx.xx.xx:5555/MSCRMServices/2007/AD/CrmDiscoveryService.asmx?wsdl'.
Source=System.ServiceModel
StackTrace:
at System.ServiceModel.Description.MetadataExchangeClient.MetadataRetriever.Retrieve(TimeoutHelper timeoutHelper)
at System.ServiceModel.Description.MetadataExchangeClient.ResolveNext(ResolveCallState resolveCallState)
at System.ServiceModel.Description.MetadataExchangeClient.GetMetadata(MetadataRetriever retriever)
at System.ServiceModel.Description.MetadataExchangeClient.GetMetadata(Uri address, MetadataExchangeClientMode mode)
at Microsoft.Xrm.Sdk.Client.ServiceMetadataUtility.RetrieveServiceEndpoints(Type contractType, Uri serviceUri)
at Microsoft.Xrm.Sdk.Client.ServiceConfiguration`1..ctor(Uri serviceUri)
at Microsoft.Xrm.Sdk.Client.DiscoveryServiceConfiguration..ctor(Uri serviceUri)
at Microsoft.Xrm.Sdk.Client.ServiceConfigurationFactory.CreateConfiguration[TService](Uri serviceUri)
at IOMG.OneMann.CRM.Organization.OpenConnection(String ServerName, String CRMFriendlyName, ClientCredentials Credentials) in C:\Projects\eServices Sandbox\Nigel\CRM2011Test\IOMG.OneMann.CRM2011.BaseAdapter\Organization.vb:line 118
at IOMG.OneMann.CRM.Organization..ctor(String ConfigurationSectionName) in C:\Projects\eServices Sandbox\Nigel\CRM2011Test\IOMG.OneMann.CRM2011.BaseAdapter\Organization.vb:line 58
at CRM2011Test.MainForm.MainForm_Load(Object sender, EventArgs e) in C:\Projects\eServices Sandbox\Nigel\CRM2011Test\CRM2011Test\MainForm.vb:line 33
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at CRM2011Test.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.Net.WebException
Message=The remote server returned an error: (401) Unauthorized.
Source=System
StackTrace:
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Description.MetadataExchangeClient.MetadataLocationRetriever.DownloadMetadata(TimeoutHelper timeoutHelper)
at System.ServiceModel.Description.MetadataExchangeClient.MetadataRetriever.Retrieve(TimeoutHelper timeoutHelper)
InnerException:Nigel T
ตอบทั้งหมด
-
26 เมษายน 2555 10:00ผู้ดูแล
Hi,
are you able to browse CrmDiscoveryService.asmx throught IE in that machine ??
Mahain : Check My Blog
Follow me on Twitter
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question. -
26 เมษายน 2555 10:14Yes. If I key in the URL if the discovery service in IE, I get prompted for a usercode and password. Once I have supplied this it works fine.
Nigel T
-
13 สิงหาคม 2555 6:26Were you able to resolve this?
-Abhijeet