Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quick and easy implementation of a WCF web service, given wsdl?

I'm writing a client to access a SOAP webservice, that will be hosted by a third party. I have the WSDL and XSD that define the interface and the data.

I've had no problem in creating a service reference from the WSDL, but I'm having a problem in building a simple web service that implements it, that I can use to test against. (The third party's service isn't ready, yet, but even were it running, I'd still like to do my initial testing against my own test server, not against theirs.)

I've browsed around, and apparently I can use svcutil to generate an interface for the service:

svcutil.exe thewsdl.wsdl thexsd.xsd /language:c# /out:ITestService.cs

This generates a file containing the service interface definition. But now what?

I figured the easiest way to go would be to build a self-hosted service, so I created a new console app, and in it I implemented a class derived from the service interface definition, and fired it up with a ServiceHost.

It runs, and while it was running I was able to create a Service Reference in my client app. But when I try to call it, from the client app, I get an error:

The provided URI scheme 'http' is invalid; expected 'https'.

What is the easiest way to get around this? Is there a simple way to simply turn off authentication and authorization, and simply allow unrestricted access?

EDITED:

I'm adding a bounty to this, as the original question seems to have attracted no attention.

But let's get to the crux. I am trying to write a client against a customer's SOAP service. As a part of the development, I want to create my own test WCF service, that implements the same WSDL.

So I have a downloaded .wsdl file, and an associated .xsd file, and with them I want to create a service that I can test against, with VS2010's debugger.

It's not important to me whether this service runs standalone, or within IIS, or that it be production stable. All I want is a service that accepts the requests that the customer's site would accept, and return the responses to my client that I need it to return, in order to test my handling of them.

How do I get there? I've tried adding a WCF Service Library, and then using svcutil.exe within it to add my new service, but it doesn't seem to populate the app.config with the server-side boilerplate, and my attempts to reconstruct it haven't worked.

like image 860
Jeff Dege Avatar asked Jun 27 '12 22:06

Jeff Dege


People also ask

What is WSDL in WCF service?

WSDL stands for Web Service Description Language. The WCF service exposes the WSDL document for the clients, to generate proxies and the configuration file. The WSDL file provides the following information for the consumers of the WCF service.

Does WCF use WSDL?

You can use WCF to export WSDL documents from a ServiceDescription instance for your service. WSDL documents are automatically generated for your service when you publish metadata endpoints.

How do I create a SOAP based WCF service?

STEP 1: Create a new WCF service application. Configure service for both basicHttpBinding and webHttpBinding, So in Web. Config file define two endpoints - one each for SOAP and REST. The binding for SOAP is basicHttpBinding and for REST is webHttpBinding.


1 Answers

Since you want a full fledged service to call instead of mocking it.

Follow these steps:

  1. Create new "WCF Service Application" project
  2. Copy wsdl and xsd into project
  3. select your wsdl file and look in the properties section and copy location from full path
  4. Right click on the project in solution explorer and select "Add Service Reference..."
  5. For the service address, paste the location of your wsdl that was copied in previous step and hit go. It should show the operations you are expecting for the service.
  6. hit ok
  7. It should generate all the objects for you including the interface and config file (although at this point is client side in the config- we will have to switch this to be the service)
  8. Now you should add the service config section in the system.serviceModel section. Since I don't know the specifics of your wsdl what you should do is create the services node inside the system.serviceModel section and copy the endpoint node from the client node generated. For example below of services node, you can blank out the address for now:
 <system.serviceModel>
    <services>
      <service name="YourService">
        <endpoint address=""
               binding="basicHttpBinding" bindingConfiguration="WeatherSoap"
               contract="ServiceReference1.WeatherSoap" name="WeatherSoap" />      
      </service>
  1. delete the client node in the config
  2. In the service, it is implementing a different interface when it generated the project so you will want to replace the interface implemented with the one listed in the contract attribute in the endpoint above. Then implement its members and it should explode out the operations available. You can fill in whatever you want the service operations to return.
  3. depending on what the wsdl has in it, we may need to do a few more things to allow the necessary bindings to run - like setting up for wsHttpbinding, netTCPbinding, etc.
like image 56
Chris Holwerda Avatar answered Jan 31 '23 19:01

Chris Holwerda