我創建了一個簡單的wcf服務,它使用高級開發人員工具從crm 4.0中檢索數據。我使用linq成功查詢了數據。這些類是使用crmsvcutil生成的。但是,當我將它轉換爲下面的wcf服務時,它不斷崩潰。crm高級開發人員工具與WCF不起作用
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;
}
在WCF服務主機中,服務已停止,但它也顯示Entities.CmsDataService也停止。當我點擊這個時,附加信息說服務(Entities.CmsDataService)不能啓動。該服務沒有定義端點。請在config文件中添加至少一個服務端點,然後重試。
正如事情站在我的app.config看起來像下面。 那麼,如何以及在哪裏添加自動生成的類的配置文件中的端點,以便它們與WCF很好地協同工作?或者我是否需要進行其他更改? 請在您的解釋中詳細說明。像往常一樣,感謝你提前。
<?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>
Definetely您endpoind配置是否正確。我有點與'Entities.CmsDataService'混淆。絕對不清楚這個名字來自哪裏。應該有像'CRMDataRetrieval.CRMDataService'這樣的東西。
而我不喜歡類名DataContext。它應該是生成類,但可能與其他.Net命名空間發生命名衝突,如System.Data.Linq – paramosh 2012-02-29 12:06:02
實體是包含crmsvcutil生成的所有類的文件夾,我使用using語句將其包含在我的項目中。 CmsDataServices碰巧是那些自動生成的類之一。你如何建議我沒有DataConext?我很高興嘗試一下。你能提供詳細信息嗎?感謝您的輸入。 – 2012-02-29 13:42:27
快速注意,如果有一個自動生成的類DataContext,我該如何去包含和使用它?請提供步驟 – 2012-02-29 13:53:16