2011-07-27 99 views
0

我試圖從無法使用.Net 4程序集的SSIS 2008腳本組件連接到CRM 2011 Web服務端點。這就排除了.Net 4 SDK,所以我一直在嘗試創建一個代理類用於直接針對2011 WS。我已經通過將代理類放入它自己的程序集中來獲得代碼,但它依賴於從app.config(方法1)中讀取SSIS程序包無法使用的WS地址(這些用戶可配置的屬性需要存儲在SSIS變量中,以便客戶可以修改它們以在其環境中工作)。SSIS 2008 - 使用腳本組件連接到CRM 2011 Web服務

我想弄清楚如何從SSIS包內讀取數據的app.config ...

或者我需要得到類似方法2工作,但我不知道爲什麼服務器投擲錯誤它。憑據是正確的。 OrganizationServiceClient方法有幾個重載,我嘗試過,並沒有工作。這是我得到它最接近的工作。誰能告訴我我做錯了什麼?

  //Method 1: This code works but relies on pulling the endpoint address from the app.config (SSIS can’t use this method) 
     //OrganizationServiceClient serviceClient = new OrganizationServiceClient("CustomBinding_IOrganizationService"); 
     //serviceClient.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential() { Domain="MyDomain", UserName="administrator", Password="*****" }; 

//Method 2: This method throws this error: 
//Could not connect to https:// MYSERVER/XrmServices/2011/Organization.svc. TCP error code 10061: No connection could be made because the target machine actively refused it. 
     string url = "https:// MYSERVER/XrmServices/2011/Organization.svc"; 
     BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport); 
     binding.MaxReceivedMessageSize = 2147483647; 
     OrganizationServiceClient serviceClient = new OrganizationServiceClient(binding, new EndpointAddress(url)); 
     serviceClient.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential() { Domain=" MyDomain ", UserName="administrator", Password="******" }; 

      //this code is common between the two techniques above 
     KeyValuePairOfstringanyType[] attributes = new KeyValuePairOfstringanyType[1]; 
     attributes[0] = new KeyValuePairOfstringanyType(); 
     attributes[0].key = "name"; 
     attributes[0].value = "MyTestAccount"; 

     Entity newAccount = new Entity(); 
     newAccount.LogicalName = "account"; 
     newAccount.Attributes = attributes; 
     serviceClient.Create(newAccount); 

下的app.config的部分(由上述方法1中使用):

<client> 
     <endpoint address="http://MYSERVER/XRMServices/2011/Organization.svc" 
      binding="customBinding" bindingConfiguration="CustomBinding_IOrganizationService" 
      contract="IOrganizationService" name="CustomBinding_IOrganizationService"> 
      <identity> 
       <userPrincipalName value="*******" /> 
      </identity> 
     </endpoint> 
    </client> 

回答