2012-02-29 72 views
0

我創建了一個簡單的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> 
+0

Definetely您endpoind配置是否正確。我有點與'Entities.CmsDataService'混淆。絕對不清楚這個名字來自哪裏。應該有像'CRMDataRetrieval.CRMDataService'這樣的東西。
而我不喜歡類名DataContext。它應該是生成類,但可能與其他.Net命名空間發生命名衝突,如System.Data.Linq – paramosh 2012-02-29 12:06:02

+0

實體是包含crmsvcutil生成的所有類的文件夾,我使用using語句將其包含在我的項目中。 CmsDataServices碰巧是那些自動生成的類之一。你如何建議我沒有DataConext?我很高興嘗試一下。你能提供詳細信息嗎?感謝您的輸入。 – 2012-02-29 13:42:27

+0

快速注意,如果有一個自動生成的類DataContext,我該如何去包含和使用它?請提供步驟 – 2012-02-29 13:53:16

回答

0

看看crmsvcutil parameters。有/ dataContextPrefix和/ dataContextClassName。使用這些參數爲生成的數據上下文設置正確的名稱。因爲它描述here

CrmConnection crmc = CrmConnection.Parse("Authentication Type=Passport; Server=https://" + org + ".crm.dynamics.com/" + org + "; User ID=myuser; Password=mypassword; Device ID=mydeviceid; Device Password=mydevicepassword"); 
var yourDataContext = new GeneratedDataContext(crmc); 

不幸的是我沒有安裝CRM 4.0使用產生的上下文。但我可以在2011年CRM提供代碼:

namespace CRMDataRetrieval 
{ 
    public class CRMDataService : ICRMData 
    { 
     public string getValue() 
     { 
      var connection = CrmConnection.Parse("Url=https://orgname.crm.dynamics.com; Username=OpenId; Password=; DeviceID=####; DevicePassword=####"); 
      var service = new OrganizationService(connection); 
      MyServiceContext context = new MyServiceContext(service); 

      string name = null; 
      var query = from n in context.ContactSet 
         where n.ContactId == new Guid("00000000-0000-0000-0000-000000000000") 
         select n.FullName; 
      foreach (var result in query) 
       name = result; 

      return name; 
     } 
    } 
} 

我用你提供的端點配置。

生成類的我用

crmsvcutil.exe /url:https://orgname.crm.dynamics.com/XRMServices/2011/Organization.svc /out:GeneratedCode.cs /n:MyCrmNamespace /u:"OpenId" /p:"####" /serviceContextName:MyServiceContext /di:#### /dp:#### 
+0

這爲我工作。我做的唯一更改是刪除了自動生成的cmsdatacontext類,並且在放棄上面創建的datacontext類時使用crmsvcutil時沒有用處並指定servicecontext。謝謝你的幫助。 – 2012-03-01 15:41:03

0

可以調出一個世界你好端點和消費呢?一旦你有了,你可以使用你已經寫好的工作代碼。 (除非crmsvcutil產生一些類,設計用於承載WCF終結,我不知道呢?)

我同意paramosh - 「Entities.CmsDataService」不是服務的名稱我希望給你的榜樣。我會期待'CRMDataRetrieval.CRMDataService'