[英]SSIS script task soap web service call error
我在SSIS腳本任務中調用基於soap的Web服務。 Web服務需要用戶名,密碼和GUID才能正常工作。 在通過SSIS腳本任務調用Web服務之前,我已經成功地從控制台應用程序調用了Web服務。 這是我的C語言代碼:
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服務從腳本開始工作需要什么? 問候。
嘗試使用這種方式:
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");
問題在於“腳本任務”不接受app.config,因此您的配置沒有發揮作用。 請嘗試設置代碼中的所有組件,如下所示:
EndpointAddress endpointAdress = new
EndpointAddress("https://webservices.nbs.rs/CommunicationOfficeService1_0/CompanyAccountXmlService.asmx");
BasicHttpBinding binding1 = new BasicHttpBinding();
binding1.Security.Mode = BasicHttpSecurityMode.Transport;
var client = new ServiceReference.CompanyAccountXmlServiceSoapClient(binding1, endpointAdress);
如果客戶創建得很好,那么您就很好了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.