Search code examples
.netwcfweb-servicessoapsoapui

WCF programming with SoapUI


I am trying my first WCF program and I am using SoapUI to immitate a third party's Host. I have a fundamental question as well as a programming question assuming my I am correct in my assumption about my first question.

Fundamental Question This third party gave me their .wsdl Which I was able to load into SoapUI. My assumption is that with their web service definition language in SoapUI - SoapUI is mocking their actual service that will be in place sometime later. So I should be using my windows service as the 'client' to send messages to SoapUI, right?

Background information: My windows service will eventually need to be able to send soap messages to this host service that is sitting on a different server. I will also need to host my own WCF service so the third party service can send messages to me when it needs to. - but I will deal with that once I get the Client part done

Another Question: All the examples I see on MSDN are using WCF Libraries. There is also WCF Service Application project type. Which one would be appropriate for what I am trying to do?

Process I have a windows service in my solution. I then added a WCF Service Application, and added a service reference in my windows service referencing my new web service. Do I even need to do this for the actual sending of messages to SoapUI? I would think I would only need to host this WCF service for me receiving messages from their (the third party's) Service.

If I am correct about that, I would only need to make a WCF Client. However, In the example on MSDN. Their solution has in it a Client/Host/ and WCF Lib. And in the Client there is a reference to the WCF Lib. It then instantiates a new instance of the 'Library's client'

   Sub Main()
        ' Step 1: Create an instance of the WCF proxy
        Dim Client As New CalculatorClient()

        'Step 2: Call the service operations.
        'Call the Add service operation.

        Console.WriteLine("******** This is the Client **********")


        Console.WriteLine("Enter a Double")
        Dim value1 As Double = Console.ReadLine()
        Console.WriteLine("Enter another Double")
        Dim value2 As Double = Console.ReadLine()

        Dim result As Double = Client.Add(value1, value2)
        Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result)

        'Call the Subtract service operation.
        result = Client.Subtract(value1, value2)
        Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result)

        'Call the Multiply service operation.
        result = Client.Multiply(value1, value2)
        Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result)

        'Call the Divide service operation.
        result = Client.Divide(value1, value2)
        Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result)

        ' Step 3: Closing the client gracefully closes the connection and cleans up resources.
        Client.Close()

        Console.WriteLine()
        Console.WriteLine("Press <ENTER> to terminate client.")
        Console.ReadLine()
    End Sub

So this leads me to believe that even if I wasn't planning on receiving messages from the third party service, I would still need to to Host a WCF service, so I am able to add the service reference to my windows service so I can instantiate a client and send messages to the third party service, is that correct?


Solution

  • I'm not that familiar with SoapUI, but my understanding is that it allows you to test web services by acting as a client, and calls an available service. It could be mocking the service, but I'm not familiar enough with SoapUI to address that with any level of intelligence. If the third party has not yet published their service, I'm not sure how they provided you a WSDL, and it doesn't make a lot of sense to worry about client implementation until you have a service to test against. Of course, if SoapUI can mock the service, then you're good to go.

    WCF Libraries are nothing more than WCF as a DLL. This DLL will need to be hosted in some manner, and if you're using a Windows Service then a WCF Library is just fine. A WCF Service Application is an ASP.NET website that hosts a WCF service - if you were using IIS, the WCF Service Application would be a good starting point, but you're not, so stick with the WCF Service Library.

    Since the WCF Library in and of itself is not usable, it needs to be hosted. This is why the example you refer to has a hosting part and a client part - the library needs to be hosted in order for the WCF service to be consumed.

    So, for the first part of your project (sending the message to the third party), all your Windows Service needs is a reference to that service, because it's acting as a client.

    For the second part, where you need to receive messages from the third party, then you would need to host your own WCF service in your Windows Service.

    In a nutshell, the client functionality does not need to be hosted - only the WCF service itself needs to be hosted.