Pages

Wednesday, November 21, 2012

IncludeExceptionDetailInFaults - Display Hidden Error

Create a simple web application to add contact data into the CRM system using c# and IOrganizationService Web Service.

1)Create Empty web application

2)Add References
microsoft.xrm.sdk.dll
microsoft.crm.sdk.proxy.dll
System.Runtime.Serialization
System.ServieModel

3)button click code
using System.ServiceModel.Description;
using Microsoft.Xrm.Sdk.Client;
using System.Net;
using Microsoft.Xrm.Sdk;

try
            {
                ClientCredentials Credentials = new ClientCredentials();
                Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
                Uri OrganizationUri = new Uri("http://<Server_Name>/<Organization_Name>/XRMServices/2011/Organization.svc");
                Uri HomeRealmUri = null;

                using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, null))
                {
                    IOrganizationService service = (IOrganizationService)serviceProxy;
                    Entity contact = new Entity("President");
                    contact["gfirstname"] = txtFirstName.Text.ToString();
                    contact["glastname"] = txtLastName.Text.ToString();
                    contact["gaddress1"] = txtAddress.Text.ToString();
                    contact["gcity"] = txtCity.Text.ToString();
                    contact["gstate"] = "NE";
                    contact["gzipcode"] = "68123";
                    Guid newContactId = service.Create(contact);

                    txtFirstName.Text = "";
                    txtLastName.Text = "";
                    txtAddress.Text = "";
                    txtCity.Text = "";
                    txtState.Text = "";
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

4)Run, the system will produce the following error

The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs.


Error from the CRM side hidden error. May caused by an invalid username and password combination.
To display the hidden error, Edit the web.config for the CRM server which is usually located at: C:\Program Files\Microsoft Dynamics CRM\CRMWeb\web.config

<configuration>
  <system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    <behaviors>
      <serviceBehaviors>
        <behavior name="CreateContactDataEntry">
            <serviceMetadata httpGetEnabled="true" />
            <serviceThrottling maxConcurrentCalls="65536" maxConcurrentSessions="65536" maxConcurrentInstances="65536" />
            <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

3 comments:

Unknown said...

Need to discuss more on this error to you. Can you let me know your contact number so that I can call you back. Otherwise you can email me your contact details to satiraji@gmail.com

makdns said...

i prefer comments, let me know what is your question, i will try to answer you.

Anonymous said...

I want to call you to discuss it, I can call 24x7.

Post a Comment