I created a simple wcf service that retrieves data from crm 4.0 using the advanced developer tools. I queried the data successfully using linq. The classes were generated using crmsvcutil. However, when I converted this to a wcf service as below it keeps crashing.
namespace CRMDataRetrieval
{
[ServiceContract]
public interface ICRMData
{
[OperationContract]
string getValue();
}
public class CRMDataService : ICRMData
{
public string getValue()
{
DataContext context = new DataContext("entities"); //entities is name of classes that were generated by crmsvcutil
string name = null;
var query = from n in context.contacts
where n.acctNum == "01218515"
select n.nickname;
foreach (var result in query)
name = result;
return name;
}
In the WCF Service Host, the service is stopped but it also shows Entities.CmsDataService as being stopped as well. When i click on this, the additional Information says that The service(Entities.CmsDataService) cannot be started. This service has no endpoint defined. Please add at least one endpoint for the service in config file and try again.
As things stand my app.config looks like below. So how and where would I add the endpoints in the config file for the autogenerated classes so that they work nicely with WCF? or would I need to make any other changes? Please be detailed in your explanation. As usual, thanking you in advance.
<?xml version="1.0"?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="entities" connectionString="Authentication Type=ad; Server=http://****; User ID=*\*******; Password=*******"/>
</connectionStrings>
<system.web>
<compilation debug="true"/>
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<bindings />
<client />
<services>
<service name="CRMDataRetrieval.CRMDataService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:7432/account"/>
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint name="wsHttpBinding_ICRMData" address="ws" binding="wsHttpBinding" contract="CRMDataRetrieval.ICRMData"/>
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>
Look at crmsvcutil parameters. There are /dataContextPrefix and /dataContextClassName. Use these parameters to set proper name for generated data context. Use the generated context as it described here
Unfortunately I don’t have CRM 4.0 installed. But I can provide code for CRM 2011:
I used endpoint configuration you provided.
To generate classes I used