2017-01-23 123 views
0

我在SSIS腳本任務中調用基於soap的Web服務。 Web服務需要一個用戶名,密碼和一個GUID才能工作。在從SSIS腳本任務調用Web服務之前,我已經從控制檯應用程序中調用Web服務併成功。 這是我的C代碼犀利:SSIS腳本任務soap web服務調用錯誤

public void Main() 
     { 
      // TODO: Add your code here 

         // TODO: Add your code here 
      MessageBox.Show((string)Dts.Variables["ServiceDateStart"].Value); 

      string userName = "xxx"; 
      string password = "xxx"; 
      string licenceID = "xxx"; 
      ServiceReference.AuthenticationHeader a = new ServiceReference.AuthenticationHeader(); 
      a.LicenceID = new Guid(licenceID); 
      a.UserName = userName; 
      a.Password = password; 
      ServiceReference.CompanyAccountXmlServiceSoapClient service = new ServiceReference.CompanyAccountXmlServiceSoapClient(); 

      string result; 
      long numberOfResults; 
      int counter1 = 0; 
      int counter2 = 19; 



      do 
      { 



       result = service.GetCompanyAccountUpdated(a, (string)Dts.Variables["ServiceDateStart"].Value, (string)Dts.Variables["ServiceDateEnd"].Value, counter1, counter2); 
       //result = service.GetCompanyAccountUpdated(a, "20150101", "20150107", counter1, counter2); 
       counter1 = counter1 + 20; 
       counter2 = counter2 + 20; 



       using (System.IO.StreamWriter file = 
     new System.IO.StreamWriter(@"C:\Users\jkrneta\Documents\GetCompanyAccountUpdated.txt", true)) 
      { 


       file.WriteLine(result); 


      } 

      } while (!result.Equals("<CompanyAccountDataSet />")); 


      Dts.TaskResult = (int)ScriptResults.Success; 
     } 

就行,我調用Web服務的代碼失敗:

ServiceReference.CompanyAccountXmlServiceSoapClient service = new ServiceReference.CompanyAccountXmlServiceSoapClient(); 

這是我的app.config文件:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
     <bindings> 
      <basicHttpBinding> 
       <binding name="CompanyAccountXmlServiceSoap"> 
        <security mode="Transport" /> 
       </binding> 
       <binding name="CompanyAccountXmlServiceSoap1" /> 
      </basicHttpBinding> 
     </bindings> 
     <client> 
      <endpoint address="https://webservices.nbs.rs/CommunicationOfficeService1_0/CompanyAccountXmlService.asmx" 
       binding="basicHttpBinding" bindingConfiguration="CompanyAccountXmlServiceSoap" 
       contract="ServiceReference.CompanyAccountXmlServiceSoap" name="CompanyAccountXmlServiceSoap" /> 
     </client> 
    </system.serviceModel> 
</configuration> 

的我在調試模式下運行服務時遇到的錯誤是:

在ServiceModel 客戶端配置部分找不到引用合同 'ServiceReference.CompanyAccountXmlServiceSoap'的默認端點元素。這可能是因爲沒有爲您的應用程序找到配置 文件,或者因爲在客戶端元素中找不到與此合同相匹配的端點元素 。

什麼是需要使我的SSIS Web服務腳本工作? 此致敬禮。

回答

0

嘗試用這樣的方式:

ServiceReference.CompanyAccountXmlServiceSoapClient service = 
new ServiceReference.CompanyAccountXmlServiceSoapClient("CompanyAccountXmlServiceSoap"); 

其他選項是:

Reload the service reference of your project. 

只是給你一個想法:

在我自己的經歷我做一個端點地址設置到我的代碼像這樣:

service.Endpoint.Address = new System.ServiceModel.EndpointAddress("https://webservices.nbs.rs/CommunicationOfficeService1_0/CompanyAccountXmlService.asmx"); 
+0

嗨,我嘗試了兩個建議,但得到了相同的錯誤...我會嘗試手動設置Web服務,看看是否可行... –