My WCF service exposes this function
public SerialNumberInfo GetSerialNumberInfo(string serialNumber) { }
Is there a way to enable HTTP GET on my WCF service? Example:
http://localhost:8004/MyService/GetSerialNumberInfo?serialNumber=4
yes, you need to use the webHttpBinding on your WCF service.
See the WCF REST Starter Kit for more information on REST Support in WCF.
REST in WCF
Overview of REST in WCF
Series of screencasts on how to use REST in WCF
If you're hosting your service in IIS, you need to create a separate *.svc file for the REST service (let's call it RESTService.svc), which contains:
<%# ServiceHost Service="YourServiceName" Language="C#" debug="False"
Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>
Now you should be able to connect to the URL
http://localhost:8004/MyService/RESTService.svc
and get your data RESTfully.
Marc
What you want to do sounds like building a RESTful service with WCF. Check out the following article on MSDN, it has all the details:
A Guide to Designing and Building RESTful Web Services with WCF 3.5
Related
I have an old ASP.NET app connecting to a .NET Remoting service. I'd replaced the .NET Remoting service to a WCF service. I have the original WSDL and I've generated a WCF service by the help of svcutil. I don't know whether the client will able to connect and call the WCF service without changing its code.
Is it possible to solve this problem, please?
A service can be both a remoting service and a WCF service at the same time.
Just configure it with RemotingServices as usual for remoting.
Then decorate with OperationContract / ServiceContract and construct with ServiceHost and you can create clients for both techniques, just that remoting is TCP only.
WCF and Remoting are different paradigms. So if you changed your Remoting server to .NET WCF service, you will have to change the client code to use the wsdl generated client
look at https://learn.microsoft.com/en-us/dotnet/framework/wcf/migrating-from-net-remoting-to-wcf#Client_Comp. it should not be difficult
I've this WCF service hosted in a Sharepoint 2010 web application. The WCF has been created using the following factory:
Factory="Microsoft.SharePoint.Client.Services.MultipleBaseAddressWebServiceHostFactory, Microsoft.SharePoint.Client.ServerRuntime, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
As you can see this is creating a REST-type service. Because we needed to consume it client-side via jQuery.
Now we also need to access it from a .NET project (WinForms). I've tried adding the Service Reference in VS but it doesn't find anything. I guess that's because it's not a SOAP service right?
So how can I consume it in C# .NET project without breaking the existing jQuery support?
Yes, Add Service Reference does not work for WCF REST services. You have a couple of options here:
Add another endpoint to your service, a SOAP-based one, so that you'll be able to use Add Service Reference on your client. I don't know exactly what the MultipleBaseAddressWebServiceHostFactory does, but you could look how it creates its endpoint(s) and recreate that in another factory - and then add the additional SOAP endpoint
Another alternative is to share the interface definition (the service contract plus any existing data contracts) between the service implementation and the .NET client. Having that interface you can use the WebChannelFactory<T> to create a proxy to the REST service (like you'd have one for a SOAP service).
I am new to WCF and just have made a sample service. Please guide me by default WCF services are soap or restful if we not specify anywhere ? I tried to run URL of my services and got this page. I am feeling it is SOAP based. Kindly guide.
Thanks
WCF services by default are SOAP - unless you use the webHttpBinding which is REST (and this for now is the only RESTful binding). To test your SOAP based services, you cannot just navigate to an URL in your browser - you need to use a SOAP test app, like SoapUI or the WCF Test Client.
WCF Data Services and WCF RIA Services are based on webHttpBinding and thus are REST-based. REST services can be tested by just browsing to the URL - you'll get back XML that can be shown in your browser (or JSON which you can store to a file and look at)
By default, WCF services are soap based if you use the project item "WCF Service" in visual studio.
I already have a WCF service that communicates through SOAP messages now I have a requirement to modify this service such that it can be consumed from JavaScript. The client asked me to look into WCF Web Api. I don't understand what are advantages I'm going to get using WCF Web Api than WCF RESTful services. Is WCF RESTful services is enough for this job?
WCF Web API is evolution of current WCF REST services = it will be the next version of WCF REST but at this time it is still preview.
What WCF configuration settings makes WCF service, so that I can access as old ASMX web services? How can I authenticate using Authentication header what I used in Old ASMX web services?
Just use basicHttpBinding
Here is an example of the configuration:
http://msdn.microsoft.com/en-us/library/ms731347.aspx
Check this out : ASMX to WCF migration