2012-02-29 17 views
0

高度な開発ツールを使用してcrm 4.0からデータを取得する単純なwcfサービスを作成しました。私は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)を開始できないことが示されます。このサービスにはエンドポイントが定義されていません。設定ファイルに少なくとも1つのエンドポイントを追加して、もう一度試してください。

私の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

を使用するクラスを生成するには

。私は少し 'Entities.CmsDataService'と混同しています。この名前の由来は絶対に不明です。 'CRMDataRetrieval.CRMDataService'のようなものがあります。
私はクラス名DataContextが好きではありません。クラスを生成する必要がありますが、System.Data.Linqのような他の.Net名前空間とのネーミング競合が発生する可能性があります。 – paramosh

+0

Entitiesは、usingステートメントでプロジェクトに含めるcrmsvcutilによって生成されたすべてのクラスを含むフォルダです。 CmsDataServicesは、これらの自動生成クラスの1つです。 DataConextを使わずに進めることをどうお勧めしますか?私はそれを試して喜んでいる。詳細を提供できますか?あなたのご意見ありがとうございます。 –

+0

クイックメモ、自動生成されたクラスのDataContextがある場合、どうやってそれを含めて使用するのですか?これが私に役立つステップ –

答えて

0

crmsvcutil parametersを見てください。/dataContextPrefixと/ dataContextClassNameがあります。これらのパラメータを使用して、生成されたデータコンテキストの適切な名前を設定します。それは残念ながら、私はCRM 4.0がインストールされていない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 2011のコードを提供することができます。

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; 
     } 
    } 
} 

私が提供したエンドポイント構成を使用しました。私はあなたのendpoindの構成が正しいDefinetely

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

を提供してください。私が作った唯一の変更は、自動生成されていたcmsdatacontextclassを削除し、上記で作成したdatacontextクラスを破棄している間にcrmsvcutilを使用するときservicecontextを指定しなかったことです。ご協力いただきありがとうございます。 –

0

あなたはhello worldエンドポイントを持ち上げて消費できますか?これを済ませたら、既に書いた作業コードを使用することができます。 (私が気づいていないwcfエンドポイントをホストするために設計されたクラスをcrmsvcutilが生成しない限り)

私はparamoshに同意します - 'Entities.CmsDataService'は私があなたの例で与えたサービスの名前ではありません。私は 'CRMDataRetrieval.CRMDataService'を期待していたでしょう

関連する問題