The following instructions were taken, mostly, from Eric White's blog on MSDN.
The point of this post is to offer a simply no frills guide to getting a WCF web service created and working.
1. There is is some setup that needs to be done before the first WCF service can be created, I'll skip these steps here. For further information check Eric White's blog.
2. Create a folder that will host the web service, e.g. c:\myWebService
3. Open Visual Studio 2010 (or 2008).
4. Click File --> New --> Project.
5. Select the WCF Template category, and WCF Service Application.
6. Set the target .NET Framework.
7. Un-tick "Create directory for solution".
8. Name the project.
9. Choose the location that was created in step 2.
10. Debug through Visual Studio to confirm that the Web Service is working.
11. Open Internet Information Services (IIS) Manager.
12. Create an application pointing to the new Web Service.
13. Change the Authentication so that "Anonymous Authentication", "ASP.NET Impersonation", and "Windows Authentication" are Enabled.
14. Confirm that the application pool user has rights to the WCF folder.
15. Add the .svc file to the Default Document list.
16. Browse to confirm that the service is working through IIS.
28 February 2011
08 December 2010
Force CRM 4.0 Record Deletion
As standard CRM 4 deletes records, marked with deletionstatecode=2, on a 24 hourly basis.
Mitch Milam has written, an unsupported, utility that forces the deletion. The utility can be downloaded from his blog: http://blogs.infinite-x.net/2009/08/26/free-utility-run-crm-deletion-service. After installing the utility the exe can be found in \Program Files\CRM Accelerators\Run CRM Deletion Service.
There is also a utility, by Microsoft, that allows you to change the frequency of deletion and re-indexing. This utility is called Scale Group Job Editor. This tool can be downloaded from: http://code.msdn.microsoft.com/ScaleGroupJobEditor
Mitch Milam has written, an unsupported, utility that forces the deletion. The utility can be downloaded from his blog: http://blogs.infinite-x.net/2009/08/26/free-utility-run-crm-deletion-service. After installing the utility the exe can be found in \Program Files\CRM Accelerators\Run CRM Deletion Service.
There is also a utility, by Microsoft, that allows you to change the frequency of deletion and re-indexing. This utility is called Scale Group Job Editor. This tool can be downloaded from: http://code.msdn.microsoft.com/ScaleGroupJobEditor
24 November 2010
Import Organisation, change to default, gives Invalid User Authorization Error
When importing an organisation into Dynamics CRM 4.0 and making it default you sometimes come across the "Invalid Authorization error" message even though you're logged in as the System Administrator.
The following TSQL should be run on the SQL instance that hosts the CRM databases. It isn't a supported fix and I take no responsibility if it breaks your system. Remember backups are your friend!
The scripts have been taken from other resouces on the t'internet, but I can't remember where. When I find out I will acknowledge the original authors hard work.
-- Import Organisation, change default, gives Invalid User Authorization error
-- To Resolve this issue it is necessary to change the user's default organisation
--STEP 1
DECLARE @Org nvarchar(50)
set @Org = 'MSCRMORGNAME'
DECLARE @OrgDb nvarchar(150)
set @OrgDb= @Org + '_MSCRM'
DECLARE @UserName nvarchar(50)
set @UserName='DOMAIN\username'
execute ('select OrganizationId from ' + @OrgDb +'..organization where name=''' + @Org +'''')
execute ('select systemuserid, DomainName from ' + @OrgDb +'..SystemUserBase where DomainName='''+ @UserName + '''')
--STEP 2
-- User the systemuserid returned to get the correct GUID
select userid from MSCRM_CONFIG..systemuserorganizations where crmuserid = '[systemuserid]'
-- Use the userid to return the correct
select DefaultOrganizationId from MSCRM_CONFIG..systemuser where id = '[userid]'
--Use the DefaultOrganizationId and userid to update the table
update MSCRM_CONFIG..systemuser set defaultorganizationid = '[DefaultOrganizationId]' where id = '[OrganizationId]'
The following TSQL should be run on the SQL instance that hosts the CRM databases. It isn't a supported fix and I take no responsibility if it breaks your system. Remember backups are your friend!
The scripts have been taken from other resouces on the t'internet, but I can't remember where. When I find out I will acknowledge the original authors hard work.
-- Import Organisation, change default, gives Invalid User Authorization error
-- To Resolve this issue it is necessary to change the user's default organisation
--STEP 1
DECLARE @Org nvarchar(50)
set @Org = 'MSCRMORGNAME'
DECLARE @OrgDb nvarchar(150)
set @OrgDb= @Org + '_MSCRM'
DECLARE @UserName nvarchar(50)
set @UserName='DOMAIN\username'
execute ('select OrganizationId from ' + @OrgDb +'..organization where name=''' + @Org +'''')
execute ('select systemuserid, DomainName from ' + @OrgDb +'..SystemUserBase where DomainName='''+ @UserName + '''')
--STEP 2
-- User the systemuserid returned to get the correct GUID
select userid from MSCRM_CONFIG..systemuserorganizations where crmuserid = '[systemuserid]'
-- Use the userid to return the correct
select DefaultOrganizationId from MSCRM_CONFIG..systemuser where id = '[userid]'
--Use the DefaultOrganizationId and userid to update the table
update MSCRM_CONFIG..systemuser set defaultorganizationid = '[DefaultOrganizationId]' where id = '[OrganizationId]'
10 November 2010
CRM 4 ISV Web App Error Out
Sometimes when a web application has been deployed to the ISV folder within CRM it doesn't work instead it gives a Runtime Error.
To resolve this the web application's web.config file needs to be updated to include the following (immediately above the tag: </httpModules>)
<remove name="CrmAuthentication">
Note: You will probably need to comment the line out if you're testing the code through Visual Studio.
This is necessary because the ISV web application is inheriting from the parent CRM web site.
To resolve this the web application's web.config file needs to be updated to include the following (immediately above the tag: </httpModules>)
<remove name="CrmAuthentication">
Note: You will probably need to comment the line out if you're testing the code through Visual Studio.
This is necessary because the ISV web application is inheriting from the parent CRM web site.
Hosting a virtual app With a Different .Net version
An error will occur if you try and host a web application within a web site and mix the .Net versions. This is because the virtual application will attempt to inherit from it's parent. This can be switched off by editing the parent web.config as follows:
Wrap <system.web> with:
<location path="." inheritinchildapplications="false">
For Example:
<location path="." inheritinchildapplications="false">
<system.web>
...
</system.web>
</location>
Wrap <system.web> with:
<location path="." inheritinchildapplications="false">
For Example:
<location path="." inheritinchildapplications="false">
<system.web>
...
</system.web>
</location>
29 September 2010
Call CRM Web Service From JavaScript
There are instructions about calling the CRM Web Services from JavaScript in the SDK however it is necessary to define the SOAPXml that will be executed. There are several ways to define this SOAPXml:
1. Download and use the "JavaScript Web Service Calls 4.0" tool available from Stunware.
2. If you are calling the CRMService you can turn on tracing, perform the search manually, and retrieve the SOAPXml from the logs.
3. Calling the MetaDataService will not log in the tracing, an alternative to tracing is to use Fiddler. Generate code that will perform the query, turn on Fiddler and execute the code. Fiddler will show the SOAPXml executed.
The SOAPHeader must be setup correctly, to generate from within CRM JavaScript use the following:
var soapHeader = GenerateAuthenticationHeader();
This should then be injected into the SOAPXml.
Sample code (retrieve the objecttypecode from the metadata service:
//Get the servername that the current page was called from.
var fullUrl = location.href;
var slashPos = fullUrl.indexOf('/', 7);
var serverName = fullUrl.substr(7, slashPos - 7);
//Get the authentication header, CRM in built function
var soapHeader = GenerateAuthenticationHeader();
//Define the fetchXML that will get the object type code
var xmlPost = '';
xmlPost += '';
xmlPost += '';
xmlPost += soapHeader;
xmlPost += '';
xmlPost += '';
xmlPost += '';
xmlPost += '00000000-0000-0000-0000-000000000000 ';
xmlPost += 'EntityOnly ';
xmlPost += '' + entityName + ' ';
xmlPost += 'false ';
xmlPost += ' ';
xmlPost += ' ';
xmlPost += ' ';
xmlPost += ' ';
//Open the CRM metadata service
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST', 'http://' + serverName + '/mscrmservices/2007/MetadataService.asmx', false);
//Initialise the call to the web service
xmlhttp.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
xmlhttp.setRequestHeader('SOAPAction', 'http://schemas.microsoft.com/crm/2007/WebServices/Execute');
//Call the metadata service
xmlhttp.send(xmlPost);
var objectTypeCode = '-1';
objectTypeCode = xmlhttp.responseXML.selectSingleNode("//ObjectTypeCode").text;
1. Download and use the "JavaScript Web Service Calls 4.0" tool available from Stunware.
2. If you are calling the CRMService you can turn on tracing, perform the search manually, and retrieve the SOAPXml from the logs.
3. Calling the MetaDataService will not log in the tracing, an alternative to tracing is to use Fiddler. Generate code that will perform the query, turn on Fiddler and execute the code. Fiddler will show the SOAPXml executed.
The SOAPHeader must be setup correctly, to generate from within CRM JavaScript use the following:
var soapHeader = GenerateAuthenticationHeader();
This should then be injected into the SOAPXml.
Sample code (retrieve the objecttypecode from the metadata service:
//Get the servername that the current page was called from.
var fullUrl = location.href;
var slashPos = fullUrl.indexOf('/', 7);
var serverName = fullUrl.substr(7, slashPos - 7);
//Get the authentication header, CRM in built function
var soapHeader = GenerateAuthenticationHeader();
//Define the fetchXML that will get the object type code
var xmlPost = '';
xmlPost += '';
xmlPost += '
xmlPost += soapHeader;
xmlPost += '
xmlPost += '
xmlPost += '
xmlPost += '
xmlPost += '
xmlPost += '
xmlPost += '
xmlPost += '
xmlPost += '
xmlPost += '
xmlPost += '
//Open the CRM metadata service
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST', 'http://' + serverName + '/mscrmservices/2007/MetadataService.asmx', false);
//Initialise the call to the web service
xmlhttp.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
xmlhttp.setRequestHeader('SOAPAction', 'http://schemas.microsoft.com/crm/2007/WebServices/Execute');
//Call the metadata service
xmlhttp.send(xmlPost);
var objectTypeCode = '-1';
objectTypeCode = xmlhttp.responseXML.selectSingleNode("//ObjectTypeCode").text;
12 May 2010
Remove Advanced Find
I was recently asked if it is possible to remove Advanced Find from the user interface. My initial answer was: no and there's no need as a user can only search on data that they are allowed to. This didn't cut it as with Advanced Find it's possible to add columns which the users aren't supposed to see. There were some other details which I won't go into, suffice to say it had to go!
The following example will remove the advanced find but, it by an UNSUPPORTED METHOD, use it at your own risk!
This change involves adding some JavaScript to loader.aspx, before continuing make sure that it's been backed up first.
1. Open loader.aspx in a text editor of your choice.
2. Add the following JavaScript function just before the tag.
3. Locate the frame named "menuBar" and just before the end of the tag add:
4. Save and close loader.aspx and fire up CRM. The Advanced Find button has been removed from the menu-bar and the Tools menu.
Note: An IISReset may be necessary to clear the cache.
The finished result:

The following example will remove the advanced find but, it by an UNSUPPORTED METHOD, use it at your own risk!
This change involves adding some JavaScript to loader.aspx, before continuing make sure that it's been backed up first.
1. Open loader.aspx in a text editor of your choice.
2. Add the following JavaScript function just before the tag.
<script language="JavaScript" type="text/javascript">
function HideAdvancedFind()
{
//Check whether the iframe is completely loaded or not
if(document.getElementById("stage").readyState != "" && document.getElementById("stage").readyState!="loading")
{
try
{
document.frames[0].document.getElementById("btn_advfind").style.display="none";
document.frames[0].document.getElementById("_MIopenAdvFind").style.display="none";
}
catch(e)
{
}
}
}
</script>
3. Locate the frame named "menuBar" and just before the end of the tag add:
onreadystatechange="Javascript: HideAdvancedFind()"
4. Save and close loader.aspx and fire up CRM. The Advanced Find button has been removed from the menu-bar and the Tools menu.
Note: An IISReset may be necessary to clear the cache.
The finished result:
Subscribe to:
Posts (Atom)