WCF is new to me, so I am having some issues that I am having a hard time figuring out what the problem is. When I run my Web App I get an "unhandled by user code" error. I know that this is simply telling me there was a problem with my call, but I can't
seem to figure out why I am getting the error. I have posted the Codebehind below, Any help is welcome
The Error is on: Dim OrgResponse =
TryCast(dsp.Execute(OrgRequest),
RetrieveOrganizationResponse)
Using
.NET 4.0, ASP.NET, Visual Basic in Visual Studio 2012
Imports Microsoft.Xrm.Sdk
Imports Microsoft.Xrm.Sdk.Client
Imports Microsoft.Xrm.Sdk.Discovery
Imports System.ServiceModel.Description
Imports Costing_website.Microsoft.Crm.Services.Utility
Public Class About
Inherits Page
#Region "References"
Private Property CurrentOrganizationalDetail As OrganizationDetail
Private Property DiscoveryService As IDiscoveryService
Private Property OrgService As IOrganizationService
Private Property ClientCreds As ClientCredentials
Private Property DeviceCreds As ClientCredentials
Private Property IsLiveID As Boolean
#End Region
' --Build full Uri to the Discovery Service
Public Function GetDiscoveryServiceUri(ByVal serverName As String) As Uri
Dim discoSuffix As String = "/XRMServices/2011/Discovery.svc"
Return New Uri(String.Format("{0}{1}", serverName, discoSuffix))
End Function
' --Differentiate between CRM Online vs Premises
Public Function GetServerType(ByVal _uri As Uri) As AuthenticationProviderType
Return ServiceConfigurationFactory.CreateConfiguration(Of IDiscoveryService)(_uri).AuthenticationType
End Function
' --Page Load Events--
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
End Sub
'Get an instance of the discovery service configuration
Protected Sub btnDiscover_Click(sender As Object, e As EventArgs) Handles btnDiscover.Click
Dim discoUri = GetDiscoveryServiceUri(ServerURL.Text)
Dim dinfo As IServiceConfiguration(Of IDiscoveryService) = ServiceConfigurationFactory.CreateConfiguration(Of IDiscoveryService)(discoUri)
'RetrieveOrgainizationsRequest
_ClientCreds = New ClientCredentials()
Dim dsp As DiscoveryServiceProxy
If GetServerType(discoUri) = AuthenticationProviderType.LiveId Then
_ClientCreds.UserName.UserName = username.Text
_ClientCreds.UserName.Password = password.Text
_DeviceCreds = DeviceIdManager.LoadOrRegisterDevice()
dsp = New DiscoveryServiceProxy(discoUri, Nothing, _ClientCreds, _DeviceCreds)
IsLiveID = True
Else
_ClientCreds.Windows.ClientCredential.UserName = username.Text
_ClientCreds.Windows.ClientCredential.Password = password.Text
_ClientCreds.Windows.ClientCredential.Domain = domain.Text
dsp = New DiscoveryServiceProxy(dinfo, _ClientCreds)
IsLiveID = False
End If
dsp.Authenticate()
Dim OrgRequest = New RetrieveOrganizationRequest()
Dim OrgResponse = TryCast(dsp.Execute(OrgRequest), RetrieveOrganizationResponse)
comboOrgs.DataSource = OrgResponse.Detail
comboOrgs.DataBind()
End Sub
End Class
Wcf tracing gives enormous amount of data, and you can even learns using it how wcf works. In the log you will see red lines, which are the fatal errors.
NuKMaN
Member
2 Points
11 Posts
Getting an Fault Exception `1 was unhandled by user code Error in a WCF call to CRM 2011 Online
Jan 18, 2013 01:55 PM|LINK
WCF is new to me, so I am having some issues that I am having a hard time figuring out what the problem is. When I run my Web App I get an "unhandled by user code" error. I know that this is simply telling me there was a problem with my call, but I can't seem to figure out why I am getting the error. I have posted the Codebehind below, Any help is welcome
The Error is on: Dim OrgResponse = TryCast(dsp.Execute(OrgRequest), RetrieveOrganizationResponse)
Using .NET 4.0, ASP.NET, Visual Basic in Visual Studio 2012
Imports Microsoft.Xrm.Sdk Imports Microsoft.Xrm.Sdk.Client Imports Microsoft.Xrm.Sdk.Discovery Imports System.ServiceModel.Description Imports Costing_website.Microsoft.Crm.Services.Utility Public Class About Inherits Page #Region "References" Private Property CurrentOrganizationalDetail As OrganizationDetail Private Property DiscoveryService As IDiscoveryService Private Property OrgService As IOrganizationService Private Property ClientCreds As ClientCredentials Private Property DeviceCreds As ClientCredentials Private Property IsLiveID As Boolean #End Region ' --Build full Uri to the Discovery Service Public Function GetDiscoveryServiceUri(ByVal serverName As String) As Uri Dim discoSuffix As String = "/XRMServices/2011/Discovery.svc" Return New Uri(String.Format("{0}{1}", serverName, discoSuffix)) End Function ' --Differentiate between CRM Online vs Premises Public Function GetServerType(ByVal _uri As Uri) As AuthenticationProviderType Return ServiceConfigurationFactory.CreateConfiguration(Of IDiscoveryService)(_uri).AuthenticationType End Function ' --Page Load Events-- Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load End Sub 'Get an instance of the discovery service configuration Protected Sub btnDiscover_Click(sender As Object, e As EventArgs) Handles btnDiscover.Click Dim discoUri = GetDiscoveryServiceUri(ServerURL.Text) Dim dinfo As IServiceConfiguration(Of IDiscoveryService) = ServiceConfigurationFactory.CreateConfiguration(Of IDiscoveryService)(discoUri) 'RetrieveOrgainizationsRequest _ClientCreds = New ClientCredentials() Dim dsp As DiscoveryServiceProxy If GetServerType(discoUri) = AuthenticationProviderType.LiveId Then _ClientCreds.UserName.UserName = username.Text _ClientCreds.UserName.Password = password.Text _DeviceCreds = DeviceIdManager.LoadOrRegisterDevice() dsp = New DiscoveryServiceProxy(discoUri, Nothing, _ClientCreds, _DeviceCreds) IsLiveID = True Else _ClientCreds.Windows.ClientCredential.UserName = username.Text _ClientCreds.Windows.ClientCredential.Password = password.Text _ClientCreds.Windows.ClientCredential.Domain = domain.Text dsp = New DiscoveryServiceProxy(dinfo, _ClientCreds) IsLiveID = False End If dsp.Authenticate() Dim OrgRequest = New RetrieveOrganizationRequest() Dim OrgResponse = TryCast(dsp.Execute(OrgRequest), RetrieveOrganizationResponse) comboOrgs.DataSource = OrgResponse.Detail comboOrgs.DataBind() End Sub End Classstmarti
Contributor
5083 Points
1061 Posts
Re: Getting an Fault Exception `1 was unhandled by user code Error in a WCF call to CRM 2011 Onli...
Jan 18, 2013 06:25 PM|LINK
You could trace wcf. Configuring wcf tracing.
Wcf tracing gives enormous amount of data, and you can even learns using it how wcf works. In the log you will see red lines, which are the fatal errors.
You can also test wcf using the test client.