簡體   English   中英

在FitNesse測試中如何調用WCF服務?

[英]How to call WCF service in the FitNesse test?

我正在嘗試在FitNesse測試中致電WCF服務。 當我嘗試使用以下代碼初始化客戶端時:

    using (var client = new Status.StatusSoapClient())
    {
        client.Endpoint.Address = new EndpointAddress(url);
        response = client.GetProductionTicketStatus(dealerId, orderId, orderLineId);

    }

我收到一個錯誤:

System.InvalidOperationException:在ServiceModel客戶端配置部分中找不到引用合同'Status.StatusSoap'的默認終結點元素。

這是有道理的,因為.NET Framework不支持DLL的配置。

MSDN庫說:“您必須將配置代碼移入托管環境可以識別的配置文件中”。 但是我不確定FitNesse是否可以做到這一點。

所以我試圖自己創建綁定而不嘗試從配置中讀取它

    var binding = new BasicHttpBinding();
    binding.SendTimeout = new TimeSpan(0, 0, 0, 0, 100000);
    binding.OpenTimeout = new TimeSpan(0, 0, 0, 0, 100000);
    binding.MaxReceivedMessageSize = 10000;
    binding.ReaderQuotas.MaxStringContentLength = 10000;
    binding.ReaderQuotas.MaxDepth = 10000;
    binding.ReaderQuotas.MaxArrayLength = 10000;
    var endpoint = new EndpointAddress(url);
    var myClient = new Status.StatusSoapClient(binding, endpoint);
    response = myClient.GetProductionTicketStatus(dealerId, orderId, orderLineId);

但是,當我嘗試使用此代碼運行測試時,出現“測試中斷,結果不完整”的提示。 FitNesse上的錯誤。

這個答案https://stackoverflow.com/a/646177/2211481建議為testrunner制作app.config的副本。 當我將app.config復制到Runner.exe.config時,將其放入Runner文件夾並再次運行初始代碼,我得到“測試被中斷並且結果不完整”。 FitNesse再次出現錯誤。

有辦法解決嗎?

通過定義COMMAND_PATTERN使其工作,如下所述: http : //twenty6-jc.blogspot.nl/2010/07/wcf-and-fitnesse-how-to-load-clients.html

!define COMMAND_PATTERN {%m -ac:\\ projects \\ someapplication \\ acceptancetests \\ acceptancetests.dll.config -r fitSharp.Slim.Service.Runner,c:\\ tools \\ nslim \\ fitsharp.dll%p}

最后,還為testrunner復制了app.config。

我收到“測試被中斷,結果不完整。” 錯誤是由於我的代碼錯誤,我在調試后解決了該錯誤。

看到這篇文章: FitNesse App.Config

NetRunner將配置文件用於列表中的第一個dll。

例如,該行:

!path C:\Probjects\HelloWorld\bin\Debug\FitNesseHelloWorld1.dll, C:\Probjects\HelloWorld\bin\Debug\FitNesseHelloWorld2.dll

NetRunner將使用配置文件“ C:\\ Probjects \\ HelloWorld \\ bin \\ Debug \\ FitNesseHelloWorld1.dll.config”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM