2017-01-23 96 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服务,看看是否可行... –