I have a service and I need to communicate with it so I started investigating WCF. I setup the service to listen and created a client. All communication is working fine.
The service will be used by several customers. Instead of having them setup a client and go through the WCF learning curve I figured I would just wrap the client and hide all the WCF implementation. I found that inorder to get this to work they still have to include in their app.config file the service model with endpoint information.
Is there a way to completely hide the service model information? I would prefer them to simply reference my dll and start making calls. It seems unnecessary for libraries beyond my client to have to know about endpoint information.
Thanks
You can create the endpoint programmatically rather than through configuration, as in the example shown in the answer to this SO question: How do I add WCF client endpoints programmatically?
If you don't want to have wcf client settings inside your web config you will need to create settings using code. Here is sample code how to create instance to wcf client (in this case using BasicHttpBinding) without web.config:
BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress address = new EndpointAddress("http://someServer/DemoWcfService");
TestServiceClient client = new TestServiceClient(binding, address)
But I would suggest you to stay with web.config wcf client configuration because it's easy to reconfigure.
Related
i have created wcf service and client. both wcf service and client are implemented using c#. i have hosted this wcf service in both iis and windows service. while i am hosting it, i need to specify the base address either in web.config file or in design time. is it possible to specify base address at run time. how to provide it at run time?
like this can i change the service reference address at client side. how to do it in c# ?
If you're using self-hosting, then you can specify the base address in the constructor of the ServiceHost class:
Uri baseAddress = new Uri("http://........");
ServiceHost host = new ServiceHost(typeof(YourServiceClass), baseAddress);
With IIS, things get a bit trickier.... you might be able to provide a custom factory to create your service host - but that seems like a whole lot of work. In addition, with IIS, the virtual directory where your *.svc file exists really dictates the URL of your service - so providing a base address really isn't of much value.
I need to discovery automatically where is a service (provided by a WEB API - RESTFULL) in a local network.
My idea is to use the DiscoveryClient for that, but I just found some examples to WCF.
Anybody can help me about this?
DiscoveryClient uses WS-Discovery protocol which is a SOAP-based protocol.
Discovery in REST is normally implemented through Hypermedia. Or you can have a custom registry service for it.
I have a simple wcf rest service. I can test it ok using the WCF Test Client.
I created a test client of my own via svcutil.exe. This builds and runs. However, it always gives this exception when instantiating the service object:
Could not find default endpoint element that references contract
'IBookService' in the ServiceModel client configuration section. This
might be because no configuration file was found for your application,
or because no endpoint element matching this contract could be found
in the client element.
I'm basically following the tutorial here:
http://www.codeproject.com/Articles/571813/A-Beginners-Tutorial-on-Creating-WCF-REST-Services
I also cannot access the endpoints via a url when running it locally. It's unclear to me why this tutorial has a .svc file in the url when trying to access the service from a browser though. I have no .svc files anywhere.
The WCF Test Client is for testing SOAP-based services (those services using any binding other than webHttpBinding in WCF).
The WCF Test Client however is NOT capable of working with REST services.
For REST, use something like Fiddler instead.
I currently need to access WCF services from within Silverlight (3.0) application, but I need it dynamic.
What I have access to : the service interfaces (ServiceContracts) and data definitions (DataContracts).
What I need : runtime generated/created WCF client proxy.
Have some solutions?
Take a look at the WCF Dynamic Proxy Sample Project
I found this "old" post (September 16, 2008).
But I could not make it run properly under Silverlight 3.0 (didn't try with previous versions of Silverlight).
WorkSight Blog » Blog Archive » A Dynamic WCF Client Proxy in Silverlight
Let us know if any of you manages to make it work! :)
My understanding is if you follow the procedure of client access described in Understanding WCF Services In Silverlight 2, you should be able to choose which service to access at runtime, because you don't need to create proxy at client side.
A snippet from this article:
Now we may turn our attention to the
client application. To begin, let me
start off by reminding everyone that
you shouldn't ever use "Add Service
Reference" in Visual Studio for
magical service client creation. The
code is incredibly verbose, hard to
manageable, edits are prone to being
overwritten, and it's almost always
used as an excuse to not actually
learn WCF.
As I've mentioned many times already,
WCF relies on the concept of the ABC.
For both
.NET and Silverlight, you merge an
address and a binding with a contract
in a channel factory to create a
channel. This isn't just fancy
conceptual architect speak, this is
exactly what your code would look like
(the sign of really good
architecture!) Below is the .NET
version of what I mean:
BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
EndpointAddress endpointAddress = new EndpointAddress("http://localhost:1003/Person.svc");
IPersonService personService = new ChannelFactory<IPersonService>(basicHttpBinding, endpointAddress).CreateChannel();
Person person = personService.GetPersonData("F488D20B-FC27-4631-9FB9-83AF616AB5A6");
Anyone have a pointer to a C# configuration class that a .NET service can use to do configurations via an admin socket or other control port? I'd rather do this than a filewatcher on the app.config file.
We have some long running C#/.NET services (24h X 6.5 days/week) that may need to be re-configured on the fly. I'm looking for a good way to push out config changes to a .NET service
Any pointers appreciated.
Craig
How about exposing a WCF service for configuration purposes? That way you can get a nicely typed API for configuration of the service.
To expand on Manga's answer;
I'd recommend hosting a WCF endpoint on the same IIS box hosting your long running C#/.NET services. This endpoint run on an arbitrary port.
Its responsiblity would simply be to change the appconfig(s) of your running service(s). You could specify a config type decorated with DataContract to allow for a nice configuration API exposed to the client responsible for pushing the config changes.
I'm not experienced with WCF, but I've typically solved this problem by rolling my own API via RPC. Expose some methods to add/remove/update certain configuration items, throw some sort of UI on top of it, and you can update your service on the fly.