Generally after added service reference client, we need to update the service reference to get the latest changes.
I created a service and hosted in production server. This is used by some client. After some time, i changed the service (by including new methods or modify some methods) and updated in the production server. So how these are updated in the client.
Again i update in development and host the updated client?
I am assuming you are using the SOAP bindings in WCF.
It depends on the scope of the change you have made.
If you have just added new operations to an existing service this won't affect existing clients.
If your service operation expose complex types, then if you have only added new fields then most client serializers will raise events rather than throw exceptions when encountering unexpected fields, with the net result that the client should still be able to cleanly deserialise your XML.
You need to be aware however, that if you have modified existing operations, or modified or removed fields in your contract types you may have made a breaking change to your existing clients. This means that existing clients will need to be recompiled against your new service contract and then redeployed in order to continue to consume your service.
Related
I have developed a WCF service for consumption within the organization's Ethernet.
The service is currently hosted on a windows-service and is using net.tcp binding.
There are 2 operation contracts defined in the service.
The client connecting to this service is a long running windows desktop application.
Employees(>30,000) usually have this client running throughout the week from Monday morning to Friday evening straight.
During this lifetime there might be a number of calls to the wcf service in question depending on a certain user action on the main desktop client.
Let us just say 1 in every 3 actions on the main desktop application would
trigger a call to our service.
Now we are planning to deploy this window service on each employee's desktop
I am also using `autofac` as the dependency resolver container.
My WCF service instance context is `PerSession`, but ideally speaking we have both the client and service running in the same desktop (for now) so I am planning to inject the same service instance for each new session using `autofac` container.
Now am not changing the `InstanceContext` attribute on the service implementation
because in future I might deploy the same service in a different hosting environment where I would like to have a new service object instance for each session.
Like mentioned earlier the client is a long running desktop application and I have read that it is a good practise to `Open` and `Close` the proxy for each call but if I leave the service to be PerSession it will create a new service instance for each call, which might not be required given the service and client have a 1-1 mapping. Another argument is that I am planning to inject the same instance for each session in this environment, so Open & Close for each service call shouldn't matter ?
So which approach should I take, make the service `Singleton` and Open Close for each call or
Open the client-side proxy when the desktop application loads/first service call and then Close it only when the desktop application is closed ?
My WCF service instance context is PerSession, but ideally speaking we have both the client and service running in the same desktop (for now) so I am planning to inject the same service instance for each new session using autofac container
Generally you want to avoid sharing a WCF client proxy because if it faults it becomes difficult to push (or in your case reinject) a new WCF to those parts of the code sharing the proxy. It is better to create a proxy per actor.
Now am not changing the InstanceContext attribute on the service implementation because in future I might deploy the same service in a different hosting environment where I would like to have a new service object instance for each session
I think there may be some confusion here. The InstanceContext.PerSession means that a server instance is created per WCF client proxy. That means one service instance each time you new MyClientProxy() even if you share it with 10 other objects being injected with the proxy singleton. This is irrespective of how you host it.
Like mentioned earlier the client is a long running desktop application and I have read that it is a good practise to Open and Close the proxy for each call
Incorrect. For a PerSession service that is very expensive. There is measurable cost in establishing the link to the service not to mention the overhead of creating the factories. PerSession services are per-session for a reason, it implies that the service is to maintain state between calls. For example in my PerSession services, I like to establish an expensive DB connection in the constructor that can then be utilised very quickly in later service calls. Opening/closing in this example essentially means that a new service instance is created together with a new DB connection. Slow!
Plus sharing a client proxy that is injected elsewhere sort of defeats the purpose of an injected proxy anyway. Not to mention closing it in one thread will cause a potential fault in another thread. Again note that I dislike the idea of shared proxies.
Another argument is that I am planning to inject the same instance for each session in this environment, so Open & Close for each service call shouldn't matter ?
Yes, like I said if you are going to inject then you should not call open/close. Then again you should not share in a multi-threaded environment.
So which approach should I take
Follow these guidelines
Singleton? PerCall? PerSession? That entirely depends on the nature of your service. Does it share state between method calls? Make it PerSession otherwise you could use PerCall. Don't want to create a new service instance more than once and you want to optionally share globals/singletons between method calls? Make it a Singleton
Rather than inject a shared concrete instance of the WCF client proxy, instead inject a mechanism (a factory) that when called allows each recipient to create their own WCF client proxy when required.
Do not call open/close after each call, that will hurt performance regardless of service instance mode. Even if your service is essentially compute only, repeated open/close for each method call on a Singleton service is still slow due to the start-up costs of the client proxy
Dispose the client proxy ASAP when no longer required. PerSession service instances remain on the server eating up valuable resources throughout the lifetime of the client proxy or until timeout (whichever occurs sooner).
If your service is localmachine, then you consider the NetNamedPipeBinding for it runs in Kernel mode; does not use the Network Redirector and is faster than TCP. Later when you deploy a remote service, add the TCP binding
I recommend this awesome WCF tome
We have exposed a BizTalk Schema as a WCF service for a third party vendor so that they can push messages onto our ESB. The WCF service has a single function which accepts and returns messages of that schema type. The issue is that if a response is not made in a timely manner or another message e.g. an error is generated by the ESB the third party app fails/crashes.
It doesn't really matter what is in the message as long as it is in the correct format and the data in the returned message is not used by the vendor or ourselves. The vendor also supplies its own WCF service which we can use to pass back messages should we wish to do so. I would like to modify the existing WCF service or manually create an new one which immediately returns a response but also passes the message onto the ESB for further processing.
I have created an interface from the WSDL using svcutil but cannot find any code examples of how manually create a WCF service to expose a BizTalk schema. All examples point to the wizard.
What is the code that the wizard creates? Is there an example? Thank you.
EDIT 23/08/2013
So it would appear that changing a wcf service created by the wizard is not an option nor is creating a new service manually. I have tried creating an orchestration which consumes the service and sends a response then binding that to the same receive port which works if the itinerary works but doesn't run if there is an error. Plus it only runs after the itinerary is complete which is no good. I need an immediate response.
You can change a wcf service created by the wizard, but it is generally better to use the Wizard to re-publish it using the below from the command line.
BtsWcfServicePublishingWizard -WcfServiceDescription=C:\..\WcfServiceDescription.xml
The WcfServiceDescription.xml will be under under the folder where you published the web service in \App_Data\Temp\ e.g. C:\Inetpub\wwwroot\BizTalkWcfService\App_Data\Temp\WcfServiceDescription.xml
Keeping a copy of this xml file in your source control is a good idea. Running the wizard against the one under the web service is not a good idea as it deletes and re-creates everything in the folder and so you might manage to corrupt it, so copy it out first and run against the copy.
Consider following scenario during development -
We change WCF service contracts very frequently.
There is a web application consuming these services.
We do update, service reference frequently in the web application.
But at times when we forget to do this, we have to debug our whole web application, to finally find out that, the service contract has changed.
Can we detect outdated proxy at runtime before invoking the service.
The best practice is to version your service to allow the client to connect with the interface its familiar with. Usually you keep one or two versions older online and add any breaking changes as an up-rev to the service. (e.g. /myservice/2012/01 then /myservice/2012/06). Then as new versions are created you can deprecate previous versions.
Second practice would be to implement a GetVersion() (or similar) method you can call and use for testing purposes. Make an initial call to the service and see what it's running then test against a locally stored version number and see if a conflict exists.
For more detail on this, there's a good article by Yoav Helfman that goes over handling version changes and updates.
I have posted about this kind of thing before.
Essentially one way to manage this situation is to require your service consumers to declare what version of the service interface they are expecting with each request.
Then expose a fault contract on your service of a type which will allow you to identify that a service version mismatch has occurred. This will mean that consumers can catch and then handle this specific problem accordingly.
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.....
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.