I'm integrating a product from another vendor with our existing processes.
This product interfaces with our system via an ASP.NET Web Service. As in, I need to write an ASP.NET Web Service that has the particular method names and parameters that the vendor has specified.
Simple enough, but we're wanting to migrate as much stuff as possible to WCF. I haven't used WCF much yet, but as I see it it's the replacement for ASP.NET Web Services (and other things).
Seeing as how I cannot modify the vendor's product, the only way I could write this new web service using WCF is if a WCF Service can be consumed as if it were an ASP.NET Web Service (i.e., as far as the vendor's product is concerned, it is consuming an ASP.NET Web Service).
Can WCF Services be consumed in this way?
With the service running, right click the project that will contain the WCF client proxy and select Add > Service Reference. In the Add Service Reference Dialog, type in the URL to the service you want to call and click the Go button. The dialog will display a list of services available at the address you specify.
Windows Communication Foundation (WCF) allows you to create a service that exposes a Web endpoint. Web endpoints send data by XML or JSON, there is no SOAP envelope. This topic demonstrates how to expose such an endpoint. The only way to secure a Web endpoint is to expose it through HTTPS, using transport security.
Web services support only one protocol- HTTP and HTTPS during communication, but WCF supports more protocols like- HTTP, TCP, and MSMQ that can be extended for a comprehensive solution, reliable session, and transactions. It signifies WCF is more adaptable to work together for a variety of software.
yes, web services are web services. In general WCF is more flexible and more powerful than ASP.NET, but you can get the on-the-wire message into and out of a WCF service to look exactly the same as the messages for an ASMX service. But, WCF is also different by default.
Migrating should be almost mechanical. Replace the .asmx file containing this:
<%@ WebService
Language="C#"
CodeBehind="~/App_Code/CommunicationService.cs"
Class="CommunicationService" %>
...with a .svc file containing this:
<%@ ServiceHost
Language="C#"
CodeBehind="~/App_Code/CommunicationService.cs"
Service="CommunicationService" %>
...and you are nearly done.
But, the default settings for a WCF web service are different than those for an ASP.NET web service. In particular, the XML namespaces of the incoming and outgoing messages may be different. Not everybody specifies distinct xml namespaces for their service and messages, but for those who do, migration will be an issue. The difference in behavior (WCF-vs-ASPNET) will cause apps that successfully were able to call an ASMX service, to not work with a "converted" WCF service.
This article discusses the issue in some detail, and describes a good workaround: use a custom ServiceHost.
The service host code in the article above is incomplete in that it works to fix only the request schema; you might/could also need to do something similar for the response schema.
Good luck.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With