测试一个WCF Web服务? [英] Testing a WCF web service?

查看:213
本文介绍了测试一个WCF Web服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个测试类的WCF服务。我相信,嘲笑是这个正确的术语?

I wanted to create a test class for a WCF service. I believe "mocking" is the right term for this?

我真的不知道,我认为我的方式要做到这一点是正确的方法。我一直在考虑一个URL来WCF服务,例如:

I'm not really sure that the way i think i have to do this is the correct way. I have been given a URL to a WCF service, for example:

http:://somesite.com/wcf/RealService.svc

http:://somesite.com/wcf/RealService.svc?wsdl

因此,而不是实际添加 RealService.svc 我的项目作为服务参考我只是增加了一个新的空 WCF服务我的项目名为服务1

So instead of actually adding the RealService.svc to my project as Service Reference i simply added a new empty WCF Service to my project called Service1.

然后我要使用 Wsdl.exe用(或者也许是svcutil.exe的?)工具来生成从WSDL URL的接口: HTTP :: // somesite.com/wcf/RealService.svc?wsdl

I then want to use the wsdl.exe (or maybe the svcutil.exe?) tool to generate an interface from the WSDL url: http:://somesite.com/wcf/RealService.svc?wsdl.

然后我打开 Service1.cs 文件,而不是让从 IService1.cs 继承我让它从生成的接口继承。

I then open the Service1.cs file and instead of letting is inherit from IService1.cs i let it inherit from the generated interface.

然后,而不是调用我的应用程序真正的服务,我只是叫我的服务1 类。那是多么嘲讽Web服务的工作原理..?

Then instead of calling the real service in my application i simply call my Service1 class. Is that how mocking a web service works..?

还需要弄清楚如何实际生成一个接口与SvcUtil工具工具(我读过,我不能使用Wsdl.exe用一个WCF服务吗?)。因此,任何技巧上都无任欢迎藏汉多!

Also need to figure out how to actually generate an interface with the svcutil tool (i've read that i can't use wsdl.exe for a WCF service?). So any tips on that are more than welcome aswell!

推荐答案

许多地区触及,将尝试你指出正确的路线:

Many areas to touch upon, will attempt to point you in the right directions:


  • 如果你想测试(即通过输入验证输出)WCF服务,使用Visual Studio GUI工具 WCF测试客户端(MSDN文章的这里)。

  • If you want to test (i.e. pass input, verify output) your WCF service, use the Visual Studio GUI tool WCF Test Client (MSDN article here).

如果你想嘲弄WCF服务(即单元测试组件消耗WCF服务),使用像 NMock2 嘲弄的框架,它允许你嘲笑服务接口(相关SO线程的这里)。你可以手工编写一个模拟太(通过实现接口),如果你不想使用外部框架 - 但这更多地参与

If you want to mock your WCF service (i.e. unit test your component which consumes the WCF service), use a mocking framework like NMock2 which allows you to mock the Service Interface (related SO thread here). You could hand-code a mock too (by implementing the interface), if you don't want to use an external framework - but this is more involved.

如果你想进行单元测试WCF服务(即服务,业务,数据等编写单元测试),使用流行的模拟框架(SO相关话题的这里)。

If you want to unit test your WCF service (i.e. write unit tests for service, business, data, etc.), use a popular mocking framework (related SO thread here).

要为您的WCF服务的代理,使用svcutil.exe的命令行实用程序(这里 >),你猜。该实用程序带有各种选项(语言,空间,配置文件等),所以要注意他们。

To generate a proxy for your WCF service, use the svcutil.exe command line utility (MSDN article here) as you guessed. This utility comes with various options (language, namespace, config file, etc.), so pay attention to them.

希望这有助于。

这篇关于测试一个WCF Web服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆