I have a visual studio 2008 solution with approximately 15 projects. Several of these projects have a WCF service reference to a WCF service project. Whenever I update the service project, I have to go to each of the other projects and right click the service reference and update it. Is there an easier way to do this, like a "Update All Service References In Solution" button, somewhere, somehow?
There's no such functionality, really - at least none that I'd be aware of.
You could do one of two things:
have svcutil.exe update your service references - it's a command line tool, which you can batch up, or have executed during a build process
or:
if you're controlling both ends of the communication channel, and both are .NET, you could put your service and data contracts into a separate assembly (or several), and then share those assemblies between server side and client side code. You'd have to change the way you build up your client side proxies a bit (instantiate a ChannelFactory<T> and create the channel from that factory for each service contract), but that would be a one-time effort.
Once done, any updates to the service and/or data contracts would be reflected in both the server side code, as well as your client proxy code.
The only drawback here is: it only works for .NET-to-.NET communication - if you have non-.NET clients, those are left out in the cold, obviously.....
Related
I am working on a project in which I want to use a Windows Workflow 4 State Machine. The Visual Studio solution templates and most guidance seem to steer everything towards hosting as a service in IIS that is created dynamically from send and receive activities within the workflow.
However, I would prefer to not use the send and receive activities and then host in my own WCF service which would allow me to use a Windows Service instead of IIS and use other bindings like TCP instead of HTTP and create my own interface instead of exposing MEX. In addition, it would be portable to any other hosting arrangement like in a WPF app or a console or whatever.
This feels a lot more flexible to me. Somehow, having service operations as part of the workflow seems like pretty tight coupling of two things that aren't that related. Is there any downside to my approach? I'm new to WF so I might be missing something.
Depending on the kind of workflows you are running you might need to write quite a bit of pluming code that workflow services provide for you.
Things to consider:
Are your workflows long lived?
Are you sending multiple messages to the same workflow?
Do your workflows need to survive a host restart?
Are you using Delay activities to respond to timeouts?
Do you need to be a able to retry action after error situations?
Lots of these things are automatically taken care of with a WF service and need your attention otherwise. It is certainly doable, I have done it in the past, but be aware of of what you are losing.
First please tell me is this solution structure is good as far as Architecture is concern?
I have XXXX. Business project in center.
XXXX. Contract project has a reference of it.
XXXX. Service project has reference of Contract and Business project.
Now i want my service to be hosted on flexible environments. That's why I want to put custom hosting logic in the Service > Host folder. This project will also have Custom Instance providing facility so that My service classes can be created with some parametric constructor.
Also I need to have different kind of endpoints so I also have a folder for Bindings
These 3 custom things currently suffice my requirement.
Now please guide me with some sample code snippet for Bindings/Host/Instance
I do not know what you mean by
i want my service to be hosted on flexible environments
and
I want to put custom hosting logic in the Service > Host folder
The type of hosting container used depends on the type of project (web, console, windows service, etc) which the service implementation is reference in. This is not something you want to bundle into one project, you should have a different project (or even a different solution) for each of your different service instances.
And this leads to your general solution structure. By placing the contracts as a project in your solution, you are coupling the contract assembly build (and potentially, deployment) to the build and deployment of your solution. The contracts should ideally be in their own solution so that they can be built and managed separately from your service implementation. What if at some time you need to maintain multiple versions of your contracts?
I think your approach to create a generic service which can be anything to anyone is way to complex. You should let WCF take care of this kind of work for you, create a different project at least for each of your service implementations, and defer the bindings management to deploy-time.
Additionally, unless you are writing your own custom bindings code you will not require a folder for bindings.
Bindings can (and should) be defined in configuration when you ship your endpoint, and to some extent, the decision about which transport binding to use should be an administration or management rather than a development concern.
I have two WCF services in a single solution (let's call it the service solution). I've deployed those services on a remote machine. I have another solution in which I consume those services by creating a reference to the services on the remote machine (let's call it the client solution). The code for both services is up to date on the remote machine (AFAIK), because I have deployed the most up to date code to it.
The issue is that in the service solution I can debug one of the services but not the other. The one that fails gives this error when I put a breakpoint on it.
The breakpoint will not currently be hit. The source code is different from the original version.
The question is, what could be different between the two WCF services to allow one to be debuggable and the other not.
In most examples of WCF services that use MSMQ transport it is always preferred to create a proxy manually using svcutil in Visual Studio command prompt rather than simply adding a Service Reference. When you can just reference the service by providing its endpoint address to the Add Service Reference dialog in visual studio why would you want to create a proxy with VS command prompt (since it is slightly more laborious)? I just came across this while reading WCF 4 Step by Step:
Note that you cannot easily use the Add Service Reference Wizard in
Visual Studio to add a reference to a WCF service that uses the MSMQ
transport.
Why exactly is it difficult? What exactly is the benefit (if any) of the former method of referncing a WCF service? It seems to me that creating a proxy manually is just unnecessarily complicating the task.
You don't need to pre-generate a proxy as long as you have a reference to the assemblies which define the service interface, operations, and data contracts. You can then create the proxy on the fly using ChannelFactory.
var factory = new ChannelFactory<IMyServiceInterface>("MyServiceNameInAppConfig");
var proxy = factory.CreateChannel();
This is far simpler than using svcutil. However, if the service is remote and you cannot get access to the type assemblies then you have no other choice but to generate a proxy.
Regarding your question about why it's easier to use svcutil instead of VS to generate the proxy code, without seeing the actual book it is hard to comment, but under the hood visual studio uses svcutil to generate the code anyway, so I can't see how it would be any better or worse. When you do this manually then you have more control over what gets generated I guess.
I have a server that needs to keep a small number of clients in sync. Whenever there is a change of state at the server, all the connected clients must be informed.
I am planning to use a “callback
contract”,
I can get hold of the
callback reference for each client on
the server by using
GetCallbackChanel().
I then need
to manage all these client channel
reference and call all of them when
needed.
So far so good however:
I don’t wish to block the server, so calls to the clients must be none blocking
Errors calling the client must be logged and coped with
Is there a standard WCF component to do this?
No, there is not a standard WCF component for this, at least through .NET 3.5. I can't speak to what may be available in .NET 4.0.
That said, there is a pretty straightforward way to do this. Juval Lowy, author of Programming WCF Services, describes how to do this using his WCF-based Publish-Subscribe Framework.
Basically, the idea is to create a separate WCF event service that resides in the same hosting application as your server (e.g., Windows service, IIS). When the state of your server changes, you publish the state change to the event service. The clients that need to be kept in sync subscribe to this same event via the event service. In effect, the event service becomes a broker for your server to notify clients of whatever events your server publishes.
The article I listed above has a code download, but you can also get the Publish-Subscribe Framework and a working example for free from his website, IDesign.net. Here is the link to the download. You may need to scroll your browser up just a little bit to see it as I believe their internal hyperlink is wrong.