Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing a WCF web service?

Tags:

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

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 

And:

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

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.

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.

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

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

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!

like image 565
w00 Avatar asked Mar 01 '13 09:03

w00


People also ask

Where can I find the WCF test Client?

You can typically find the WCF Test Client (WcfTestClient.exe) in the following location: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE - Community may be one of "Enterprise", "Professional" or "Community" depending on which level of Visual Studio is installed.

Can we test WCF service using postman?

After you have verified the API using Postman, use the same protocol and content to implement it with the HTTPClient object from PowerBuilder. How to use the RESTClient object to consume a WCF Service. a. To get the method and parameters to consume the WCF Service.

How do you test SVC?

Visual Studio provides you a test client to run and debug the service. To use this test client, select your service in Solution Explorer ( CustomerProfile. svc ) and, from the Debug menu, select Start Debugging (or just press F5). Visual Studio will run the code in debug mode using the WCF Test Client, as shown in ...


1 Answers

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

  • 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).

  • 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.

  • 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).

  • 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.

Hope this helps.

like image 116
Channs Avatar answered Oct 06 '22 13:10

Channs