WCF: Web Service or not? - wcf

I'm at the moment creating an ASP.NET web app which should call a WCF Service... The WCF Service have 2 methods:
Bitmap TakeScreenDump(string websiteUrl, int width, int height);
Bitmap GenerateThumbNail(Bitmap source, int width, int height);
The purpose of my ASP.NET web app is to let a user request a screenshot for a specific website, which the web app will hand over to the WCF Service.
Now is my question: Should I create the WCF Service as a Web service (http binding) ? or should I create it as a Console service (net.tcp)? My WCF Service wont be used by anyone else than me.
Whats the advantages/disadvantages of those two in this case?

It doesn't matter. The service code will be exactly the same.
It's one of the most important things about WCF that the service is separate from the binding. If you think you might want to use more than one binding, then create the service as a "WCF Service Library" project. Then you can host it in a Console Application, Windows Service, or whatever, using whichever binding you like.
In fact, there's no reason you can't do both. You can host it in a Console application using one of the HTTP bindings if you like.

Related

Calling WCF service method from browser?

Since i am new to WCF and Having configured a WCF service endpoint in IIS at Virtual Directory Api ( url goes like
http://localhost/api/taskapi.svc)
i was looking for ways to make request through web browser something like
http://localhost/api/taskapi.svc/GetCompleted
would respond with returnd data .I know this requires the binding of web service with the webHttpBinding but i don't know how to do it any help would be great ?
Use WCFSVGHoST application to test WCF applications. Application enables you to key-in parameters value and execute method of your interest.
Link for the same:
http://msdn.microsoft.com/en-us/library/bb552363.aspx

How to secure WCF web services hosted from a Windows Service?

I have a one question about WCF web service security.Currently, we are developing one android mobile project and using wcf web service for data transfer and manipulation.
We use basicHttpBinding and hosted the web service as Window Service.
We don't have any security mode at the moment and I am afraid of every one can consume our web service if they know the service address.
For example, we have one service method and that will return string value. Currently, I can add that service to other visual studio project and mobile project and we can consume any time.
//WCF Service Method
public string DoWork()
{
return "This is return string!";
}
//We can consume it like below from other dot net project by adding service reference.
//Actually, those are not real client.
ServiceReference1.WebServiceClient serv = new TestingPrj.ServiceReference1.WebServiceClient();
string result = serv.DoWork();
My question is how can I secure my web service for real clients? I don't want other projects and people to consume our web services.
The simplest method is to use Basic Authentication over SSL. Basic Authentication requires the client to have a username/password pair, which only your application will know. If the authentication is purely to know if your client is the right one (rather than knowing which user is connecting), then you can use a single, hard-coded username/password.
SSL should be used as well so the credentials don't travel the wire in plain-text and can potentially be sniffed.
Using ssl certificates is the most secure way.

wcf wp7 service reference - session/coockie

i have and app that use a wcf service reference with the enableHttpCookieContainer="true" in the binding.
enableHttpCookieContainer is not really compatible in visual studio, i need every time that i need to update to delete it.
after few searchs i founded other methods to pass cookies in the wcf requests like this:
using (new System.ServiceModel.OperationContextScope(Channel))
{
System.ServiceModel.Channels.HttpRequestMessageProperty request = new System.ServiceModel.Channels.HttpRequestMessageProperty();
request.Headers["Cookie"] = CoockieContainer;
System.ServiceModel.OperationContext.Current.OutgoingMessageProperties[System.ServiceModel.Channels.HttpRequestMessageProperty.Name] = request;
}
but this don't work for me in wp7.
my question is, what is the officially, clean, compatbile way, to have a session in wcf when use from wp7 service reference? if wcf is hosted in a windows service instead a web site, there is not session, so i really think that the enableHttpCookieContainer is a fail and not clean way...

Questions about adding a WCF service to a Windows service assembly

I have found some basic information about hosting a WCF service in a Windows service, but not much. All of my experience thus far with WCF has been in Web projects. I have a few simple questions.
I have a project which creates a windows service application. I have done a right click -> add WCF Service. This creates Service1.cs and IService1.cs.
I'm wondering why no SVC file is created in this scenario? When I add services to Web projects i get an SVC file which I can navigate to and use to consume the service.
Adding the service adds some configurations to the app.config under the services element. I'm seeing a default base address of
http://localhost:8732/Design_Time_Addresses/WindowsServiceName.services/WCFServiceName/
What does this mean? It's sort of an odd looking address. Am I supposed to change it to whatever I want?
Navigating to this address in a browser results in an unable to connect message. Does the windows service itself have to be running to talk to the WCF service?
How do I go about consuming this service from another application without an svc file?
I'm taking a guess on this first one, but I'm thinking the .svc file when hosting in IIS is to tell IIS, "Hey I have a WCF service here, please handle accordingly".
The base address is as it should be and yes you can change it if I'm not mistaken.
You can't hit the WCF service unless the Windows service is running, which is one of the dangers of hosting in a Windows service, because if the service dies somehow your WCF service is offline until you get the Windows service running again.
You consume the service the same way you do any other WCF service, just using that base address to get at it.

WCF data service hosting in Windows Form

I want to host a WCF Data Service (formerly known as ADO.NET data Service) in windows form.Is it possible? If yes,then is there any blog, which talks about it?
I know WCF can be hosted in Windows Form, but I am not sure about WCF data service, as all the examples I see, is asking to create ASP.NET web project.
-Brajesh
It is very easy to host a WCF Data Service in a WinForms application (or in my case a unit test).
// add reference to System.Data.Services
// identify your endpoint uri
Uri endpoint = new Uri("http://localhost:12345/MyDataService");
// create the data service host
DataServiceHost host = new DataServiceHost(typeof(MyDataService), new Uri[] { endpoint });