Self hosting ASMX in WCF application - How do you get the exact same SOAP produced? - wcf

This is not a question about addressing.
I have an ASMX service, defined the usual way with WebService(), WebServiceBinding() and WebMethod() attributes.
Now, I'd like to use WCF to deliver this functionality, via self-hosted solution.
I've tried using ServiceContract() and OperationContract() attributes with equivalent Namespace parameters to what is in the ASMX service and even though the WSDL generated looks similar, when a client designed to work with the ASMX service posts to the WCF version, I don't see the methods being invoked.
How can I achieve what I'm trying to do?

Related

ASMX Web service migration to wcf

We have developed the wcf service with the existing web service code. the existing customer wants to consume that service only changing the new url. They do not want to replace the proxy class. is it possible in any case.
The customer is able to consume the same with replacing the proxy and config. but he does not want to replace the proxy. please share ur comments whether it is possible or not.
You may be able to do this by configuring an endpoint using basicHttpBinding. I believe you will also need to force the use of the XML Serializer, and I don't know how to do that offhand, so someone else will have to help you with that. I'm concerned that there could still be small differences that would cause errors using the same proxy class.
On the other hand, if performance isn't the top consideration, you could create an ASMX service using the original class and method attributes from the old service. This ASMX service would then call the WCF service.
BTW, the ASMX service could call the WCF service on a fast endpoint. If they were running on the same server, they could use netNamedPipesBinding, for instance, but in any case could use netTcpBinding, which uses binary over TCP/IP. That would mitigate the performance difference from the extra hop.

Consuming WCF service (without metadata) on a non-.net platform

I have created a WCF service and hosted it through self hosting. This service doesn't have any metada published.
First Question
Can I consume it through Visual Studio, Add Service Reference? Hopefully not.
Can I consume it by creating manual proxy, i.e. ChannelFactory<ServiceContract>....?Hopefully yes.
Now in the second scenario, the client must be .Net, right?
So it implies that, to consume a wcf service on a non-.net platform, we have to expose its metadata?
Can't a WCF service without metadata, consume by Ajax client, or say Java client??
There are 3 options to consume a WCF Service:
If the service exposes a WSDL use "add service reference" from VS (or an equivalent from another platform). Note that if you do not want to expose the WSDL you could expose it just temporarly, save the WSDL in a file, and then send it to user in any platform to generate proxy from it. You can turn off the WSDL immediately after you save it. Also note that even if the WSDL is not exposed still you need to protect the web service from unauthorized access.
If this is a .Net client it can compile with the same Service Contract assembly and use ChannelFactory etc.
Any platform can send raw soap message (e.g. XML) to the service. Of course they need to know what is the right format. A WSDL can help but even without it if they have a working sample they can imitate it.
WCF provides REST (Representational State Transfer) support to consume it by non .NET client like JavaScript (AJAX), java, Objective C, web browser, etc...
Basically WCF REST is exposes methods and transferring data over the HTTP protocol and it supports all HTTP operations (GET, POST, PUT, and DELETE). This feature is making it platform independent as well as it doesn’t require metadata exposed.
Please refere below links to get more about WCF REST:
An Introduction To RESTful Services With WCF
WCF REST Programming Model Overview
WCF Rest vs. WCF SOAP
Create RESTful WCF Service API: Step By Step Guide

Not able to add a Web reference to a WCF Service library using basicHttpBinding

I have two instances of VS2010 running on same machine.One VS instance has a WCF service with basicHttpBinding.
Now as i have read in books, for calling this WCF service with basicHttpBinding, i have to Add a Web reference to it rather than Service Reference.
I ran the project containing the WCF service and from other VS instance try to add a Web reference, this is the URL which i gacve(I got it from WCFClientHost )
http://localhost:8732/Design_Time_Addresses/WcfServiceLibraryBasicHttpBinding/Service1/mex
But i get Http 400 error everytime i try to add the WCF service.
Please let know what i am doing wrong.
You should keep two things apart:
Add Service Reference adds a service interface based on the .NET 3.0 and up WCF runtime. It supports all WCF bindings - including basicHttpBinding
Add Web Reference is the old-style, .NET 1.x/2.x method of adding a reference to an ASMX web service ("ASP.NET web service"). This technology is outdated, and has been fully replaced by WCF as of .NET 3.0. ASMX only ever supported what is more or less equivalent to basicHttpBinding.
The ASMX technology is outdated, and you should only ever use this if you really can't make WCF work (but in my 3 years of writing and consuming a plethora of web services, I have never seen such a case) - avoid this unless you absolutely can't make WCF work - for whatever weird reason that might be...
The link you gave to the CodeProject article has a entirely plain wrong statement that you need to use Add Web Reference for basicHttpBinding - that is just plain NOT TRUE.

Writing a RESTful service using WCF for public usage. Is providing WSDL really necessary?

As the question suggests, is providing the WSDL really necessary, or is it more of a "nice to have" feature? I have written a RESTful service, using .Net 4.0. I see now that WSDL isn't automatically generated by adding ?wsdl... and I can't get it to either after trying various suggestions :-/
I have written several ASMX services in the past - all well and good as the WSDL is accessible automatically. I want to move away from SOAP. I would prefer to provide potential users with a Class (C#, Java versions etc..) and sample code. Is that an equally viable option? Or am I being lazy in suggesting all that?
Thanks for your opinions.
WSDL = SOAP;
REST != WSDL;
For a REST Service, WSDL is not a nice-to-have it is a cannot-have.
If you are exposing a RESTful service then WSDL does not mean anything - WSDL means you have a SOAP web service.
You can expose a SOAP web service in addition to your REST service but the WSDL would be for that service.

Converting ASMX to WCF Web Service

I need to upgrade our web services to use WCF instead of ASMX. If the signatures of the web services stays the same, will existing clients that already call the ASMX service have to change anything on their end? Is there anyway to still use WCF but not force them to change anything?
Option 1 :
Using the current ASMX's WSDL, generate the client using svcutil.exe
Grab the generated interface and create a WCF service based on this interface
Output : One new WCF endpoint configured with basicHttpBinding. Clients need to update the URL at which they're sending the messages.
Option 2 :
Refactor your ASMX code. Move all the logic into a separate DLL.
Create a WCF service and use the logic in the refactored DLL.
Output : 2 endpoints, one for ASMX and another one for WCF
If you use the BasicHttpBinding for your new WCF service, and implement the same methods with the same message structure, existing callers should be able to call into this new WCF service without any change on their part.
There's also an AspNetCompatibilityRequirements attribute in order to get around some potential compatibility issue - see the MSDN documentation on it.
Marc