Testing WCF Service endpoints hosted in BizTalk with SOAPUI
Introduction
An important aspect of building an integration solution is testing. There are different tests you need to conduct before your solution goes live. A developer will do a unit test and integration test on UAT before a functional acceptance test is done by a business analyst. There are in generally for software testing several types of tests like the mentioned unit test, integration test, functional acceptance test and tests like smoke test, performance test, and system test. Depending on the complexity of your solution you will need to do a lot of these types of test to assure the quality, stability and robustness of your solution. There are various tools available to assist you in performing these kinds of tests. In the context of BizTalk there are testing features available in Visual Studio, community tools found through CodePlex like BizUnit, tools downloadable from Microsoft like SysInternal tools and/or tools like soapUI.
SoapUI is a functional test tool build by SmartBear. This tool can be downloaded for free and is useful in testing web services. In case your BizTalk solution has web service endpoints exposed through receive ports you can use soapUI to test the behavior of your solution when you sent messages to those endpoints. You can expose web service endpoints or an orchestration as a service using the BizTalk WCF Service Publishing Wizard. This wizard comes out-of the box with BizTalk Server.
A BizTalk solution you need to build may require to have web service endpoint as an entry point for messages to be processed and/or routed to other systems or services. Or it is possible you need to expose a business process as a service. In that case you build an orchestration and expose it as a service. You can unit test the service using BizUnit and use soapUI for a functional test. In this article the functional testing with soapUI is discussed.
Scenario
To discuss and demonstrate how soapUI can be useful with regards to functional testing I will use a scenario, where a BizTalk application will serve as a kind of proxy between a client and a public REST Service endpoint.
http://i208.photobucket.com/albums/bb152/Steef-Jan/SoapUI/Scenario_zps8c812b27.png
Picture 1. Scenario diagram.
The flow a message will be as follows:
- From a client application a request for the status of a airport will be sent.
- BizTalk will map this request to a GET operation to the Restful service endpoint.
- The endpoint will provide the status of a given airport based upon the airport code provided within the request URL.
- The result will be routed back to the client application, where it will be rendered in a Windows Form.
The solution will have a WCF service endpoint to which the client application can send a request message. We will test this service endpoint using soapUI. SoapUI in this case will actually act as a client sending out a request message for certain details of an US airport.
SoapUI
SoapUI is a free and open-source tool that can be used cross-platform and thus it is not bound to just the Microsoft Platform. You can perform load, regression, and automated functional testing. The latter is of interest to functional test a BizTalk solution that has WCF service endpoints. Currently the tools is at version 5. You can read more about SoapUI itself through their website.
To perform a functional test with SoapUI in our scenario we download the tool from SmartBear and install it. Next we perform the following steps to set up a test for our BizTalk solution and test it:
- First you need to have access to WSDL of the service. The WSDL has to be imported into a soapUI Test. The import is file based so you need to save the WSDL first. So you go to the service endpoint in the browser and select WSDL. Subsequently you save the WSDL to disk.
- Next step is to create a project in soapUI. Start soapUI and right click projects. Next select New SOAP Project. Specify a name for the project and navigate to the previously saved WSDL.
http://i208.photobucket.com/albums/bb152/Steef-Jan/SoapUI/soapUI_4_zps4cc899c4.png
Picture 2. New SOAP Project.
- Once you have specified the project name and initial WSDK you click Ok. Now the sample request message will be provisioned for you. By default the setting for creating requests is enabled.
- By expanding the project you will end up with a generated request. The only thing you need to do now is set a value with the request parameter AirportCode.
http://i208.photobucket.com/albums/bb152/Steef-Jan/SoapUI/soapUI_1_zpsa71dddfa.png
Picture 3. Edit the request message.
- Since we are calling a WCF-WsHttp configured service endpoint there is another thing we need to do. Since the service we like to test with soapUI makes use of this binding we will have to configure a certain part of the soapUI project. The WCF-WsHttp makes use of WS-Addressing so we need to set the WS-A setting in the project below the request. You can click WS-A and a setting tab will pop up.
http://i208.photobucket.com/albums/bb152/Steef-Jan/SoapUI/soapUI_5_zps38aab243.png
Picture 4. WS-A settings pop up screen.
- In this screen you need to ensure the Enable/Disable WS-A addressing is checked, and set the Must understand dropdown box value to True, and check the Add default wsa:To tickbox.
http://i208.photobucket.com/albums/bb152/Steef-Jan/SoapUI/soapUI_6_zps55288a5f.png
Picture 5. Specifying the WS-A settings.
- Now the other setting, we need to consider before sending the request out and that is a security setting on the BizTalk side. Now soapUI does not support Message Security so the security mode of the WCF-WsHttp in the receive location needs to be set to None. In case it is Message Security and you sent a message you will end up with an error like:
The message could not be processed. This is most likely because the action 'http://tempuri.org/AirPortService/GetStatusRequest' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between the bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.
Note: Johan Cooper has blogged about this issue and testing WCF-Ws-Http based service with soapUI, see Calling a WCF-WSHttp service from SOAPUI.
- Now you can hit the play button.
http://i208.photobucket.com/albums/bb152/Steef-Jan/SoapUI/soapUI_2_zpsfdbf69ca.png
Picture 6. Sending the request message with soapUI.
- The result of the call will be displayed in the right pane next to the request pane.
http://i208.photobucket.com/albums/bb152/Steef-Jan/SoapUI/soapUI_7_zpsee6162ac.png
Picture 7. Response (result) from BizTalk Server.
- This result is the same as when providing the following URL in a browser:
The result in soapUI is what we have expected and we can conclude that the functionality of the BizTalk solution in this scenario is correct.
Wrap up
Functional testing is an aspect of testing that plays an essential part in assuring the solution you want to deploy adheres to the requirements of the business. In case your BizTalk solution has WCF service endpoints than soapUI is a tool that can help and save time. Instead of building your own test clients to test the service endpoints and functionality of the solution you can use soapUI. It has an intuitive user interface and rich set of features. It’s free and easy to understand how to use it for simple, functional tests of your WCF service endpoints.
Now soapUI is not limited to just WCF service endpoints it can also be used to test REST based services or other types of services; the article primarily focused on the WCF based service endpoints to demonstrate the benefit of using soapUI for functional testing.
This article has demonstrated one of the capabilities SoapUI offers for functional testing a BizTalk solution. SoapUI has a lot more to offer that what has been discussed here. It has a ton of functionality to offer with regards to testing. So in case you want to explore more its functionality than do not hesitate to visit their website and follow up on the resources they offer to learn more.
The soapUI tool is a valuable asset as a test tool. It can be even useful in combination with other tools like Fiddler and WireShark for troubleshooting web services. So having knowledge and experience with these tools can be very beneficial to your productivity.
See Also
Other suggested article to read:
Michael Stephenson has written an extensive series of blog post on testing in BizTalk Server (targeted on BizTalk 2009):
Another important place to find an extensive amount of BizTalk related articles is the TechNet Wiki itself. The best entry point is BizTalk Server Resources on the TechNet Wiki.