简体   繁体   English

在FitNesse测试中如何调用WCF服务?

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

I'm trying to call WCF service in the FitNesse test. 我正在尝试在FitNesse测试中致电WCF服务。 When I'm trying to initialize a client with the following code: 当我尝试使用以下代码初始化客户端时:

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

    }

I get an error: 我收到一个错误:

System.InvalidOperationException: Could not find default endpoint element that references contract 'Status.StatusSoap' in the ServiceModel client configuration section. System.InvalidOperationException:在ServiceModel客户端配置部分中找不到引用合同'Status.StatusSoap'的默认终结点元素。

which makes sense because .NET Framework does not support configuration for DLLs. 这是有道理的,因为.NET Framework不支持DLL的配置。

MSDN Library says: "You have to move your configuration code into the configuration file recognized by your hosting environment". MSDN库说:“您必须将配置代码移入托管环境可以识别的配置文件中”。 But I'm not sure if this is possible to be done for FitNesse. 但是我不确定FitNesse是否可以做到这一点。

So I tried to create binding myself without trying to read it from config 所以我试图自己创建绑定而不尝试从配置中读取它

    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);

But when I try to run the test with this code I get the "Testing was interrupted and results are incomplete." 但是,当我尝试使用此代码运行测试时,出现“测试中断,结果不完整”的提示。 error on FitNesse. FitNesse上的错误。

This answer https://stackoverflow.com/a/646177/2211481 suggests to make a copy of the app.config for the testrunner. 这个答案https://stackoverflow.com/a/646177/2211481建议为testrunner制作app.config的副本。 When I copy my app.config to Runner.exe.config, put it to the Runner folder and run the initial code again I get the "Testing was interrupted and results are incomplete." 当我将app.config复制到Runner.exe.config时,将其放入Runner文件夹并再次运行初始代码,我得到“测试被中断并且结果不完整”。 error on FitNesse again. FitNesse再次出现错误。

Is there a way I could solve this? 有办法解决吗?

Got it working by defining COMMAND_PATTERN as described here: http://twenty6-jc.blogspot.nl/2010/07/wcf-and-fitnesse-how-to-load-clients.html 通过定义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} !define COMMAND_PATTERN {%m -ac:\\ projects \\ someapplication \\ acceptancetests \\ acceptancetests.dll.config -r fitSharp.Slim.Service.Runner,c:\\ tools \\ nslim \\ fitsharp.dll%p}

Making a copy of the app.config for the testrunner also worked in the end. 最后,还为testrunner复制了app.config。

I was getting "Testing was interrupted and results are incomplete." 我收到“测试被中断,结果不完整。” error because of a mistake in my code which I solved after debugging. 错误是由于我的代码错误,我在调试后解决了该错误。

See this post: FitNesse App.Config 看到这篇文章: FitNesse App.Config

NetRunner uses configuration file for the first dll from the list. NetRunner将配置文件用于列表中的第一个dll。

For exampple, for the line: 例如,该行:

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

NetRunner will use configuration file "C:\\Probjects\\HelloWorld\\bin\\Debug\\FitNesseHelloWorld1.dll.config" NetRunner将使用配置文件“ C:\\ Probjects \\ HelloWorld \\ bin \\ Debug \\ FitNesseHelloWorld1.dll.config”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM