Dynamic WCF service adress with shared contracts c# - c#

How can i create wcf service at runtime, I've searched but every question and answer I found is how to consume dynamic WCF services. But I want to create new adresses on the host or change the adress/name of an existing service.
ex
If a have my wcf service at some adress http://somewhare:5751/default.svc and I like to dynamiclly create a new service on the same host with the same contract,bindings etc just another adress http://somewhare:5751/defaultCopy.svc and it's going to be persistent.
Is this possible or should I do some sort of redirect traffic to the default.svc ?
Edit:
Why I want this is just because of it will be more user friendly, the user will create his own database(SDF). I could send parameters along with the calls to the service that defines the correct database, but It would be alot nicer if a user can specify their own name of the service.

Related

wcf service domain to domain connection for post or get request

Work on wcf service.Have some services are in one host,request on domain my services are invoke perfectly,recently i change my hosting and domain but want to remain my existing domain ,request on existing domain want to invoke new hosting services,is it possible? bellow pic may describe in detail
Want to complete scenario-2's cycle?is it possible?

WCF service Single proxy instance with multiple endpoints

I developed a WCF Service hosted in a Windows Service which would send a request to the thirdparty webservice and expects a response.So all i would be given is the url/wsdl information of the thirdparty service where its hosted.
I want to implement say a test service which would give response to my request and Create a single proxy of that service by adding service reference in the visual studio to the actual service.So there can be any number of third party applications which would provide their urls in the future for communication.
My question about the WCF is can i create a single proxy client once and just send the request to a webservice based on the url on the fly ? Is it possible to use the same proxy client for both HTTP and HTTPS by just passing the binding and address parameters dyanmically ?
Once you have create the proxy you cannot change its address. You could have several open proxies, one per 3rd party. In addition a single proxy cannot be reused for http and https since they use different bindings (in addition to the reason above).
One reason for this behavior (which may or may not be relevant in your case) id that proxy can keep state with the server, for example an open security session.

WCF Application EndPoint

I quote from the MSDN:
application endpoint
An endpoint exposed by the application and that corresponds to a service contract implemented by the application.
Can somebody please explain this definition for me? Is the application endpoint the same as the service reference created by the Visual Studio?
All communication WCF service occurs through the endpoints. It provide clients access to the functionality offered by a WCF service.
Each endpoint consists of three properties:
Address (Where)
Binding (How)
Contract (What)
Endpoints can also have a set of behaviors that specify local implementation details.
endpoints concept exists both on clients and services :
A WCF services can expose multiple endpoints and a client may communicate with services with multiple endpoints.
Can somebody please explain this definition for me? Is the application
endpoint the same as the service reference created by the Visual
Studio?
When you add a service reference, Visual Studio will add a new client endpoint in your application (check updated config file). However, Visual Studio will try first to download metadata in order to list all available endpoints for an address.
Basic Explanation:
The application endpoint is the address that your clients will connect to to get to an instance of a service that implements the listed "service contract".
Further Explination:
WCF works through Interfaces, not classes. Each one of those Interfaces is known as a "Service Contract". A single class could implement more than one Interface so two service contracts could be hosted by a single class. You did not ask about this, but I thought I should get that out there too.
To answer your question, a single Interface can be connected to in multiple ways. Each of those ways you create are called Application Endpoints. Here is a practical example: You may want people to be able to connect using either HTTP for external connections or named pipes for requests generated on the same machine for higher performace. By setting up two endpoints up for a single "Service Contract" that lets you have that flexibility.

WCF Data service, some question

I've two questions on WCF Data service:
-98% of my needs are covered by the WCF Data service, I only need one business methods, is it possible to mix a WCF Data service? Or should I create a second WCF service only for this method?
-Is it possible to host a WCF Data service into an application? I've a server, and I want that this service is accessible only when the server is launched
Thank you very much
You can add service operations to your WCF Data Service: http://msdn.microsoft.com/en-us/library/cc668788.aspx
They don't have the same power as true WCF Service operations, but they should fullfil most of your needs in this area (note that they can actually return OData feeds/entries for the client consumption).
You can definitely host WCF Data Service in your own application. The overall description is here: http://msdn.microsoft.com/en-us/library/cc668805(VS.100).aspx, but there are bunch of samples around the web, just search for "host WCF Data Service".

Security on a WCF public web service

I'm building a complex, public web service in WCF that send email to a specific address, similar to a contact form but with some features.
With jQuery I get the data from the textbox and with Ajax and json I send to the web service the strings to proceed at the send.
Now, is there a good way to make it secure?
I mean.. the service is public so someone can have access to it and starting to spam on this address. Can I restrict the users to use the web service only from the correct web site?
Thanks.
IF the WCF service is hosted in the IIS you can allow calls only from a specific IP address, look at the directory security settings under IIS.
By far the simplest way is to have your web service require some type of access key in order to run the operation.
Something simple like a base64 encoded GUID would work. It doesn't even have to change. Just add a parameter called "AccessKey" or something similar. Have your app pass that and let the service validate that it is good.
Another idea is to have the web service check the http headers to see if it came from the page you authorized to use it.
Neither of those are perfect. The first one means that your "key" will be inside the html you send to the client. The second one can be spoofed.
Personally, I'd probably not bother at this level and just log what the service is doing. If the traffic counts to the service start to exceed what you think it ought to be, then I'd investigate ways to mitigate it. Most likely, given that it's a service you won't see any issues.

Categories

Resources