I'm hosting some SOAP services with WCF. How can I turn off these services via config for the purposes of maintenance, etc., and provide a friendly message to the service consumer with something like "The service you've requested is down for maintenance."?
相关问题
- How to make a .svc file write to asp.net Trace.axd
- WCF Service Using Client Certificates Requires Ano
- WCF error with net.tcp "The service endpoint faile
- WCF Service Reference Support Files Not Updating
- WCF Web Service: Upload a file, Process that file,
相关文章
- Service层和Dao层一定要对应吗?
- k8s 访问Pod 时好时坏
- WCF发布Windows服务 POST方式报错 GET方式没有问题 应该怎么解决?
- XCopy or MOVE do not work when a WCF Service runs
- Cannot use org.jvnet.jax-ws-commons.jaxws-maven-pl
- Async task does not work properly (doInBackground
- Could not find default endpoint element that refer
- The 'DbProviderFactories' section can only
How about this: create a custom ServiceBehavior to intercept my incoming requests to the service. Then, have the custom behavior check a user-defined flag in my config file, something like
<add key="IsMyServiceUp" value="true" />
and if that value returns asfalse
then throw a ServiceException with my friendly message and HTTP code of 503 - Service Unavailable.Does that sound reasonable? Then all I have to do is change the flag in my config file to specify where the service is up or down.
Okay, so I've created a new Custom Behavior that implements IOperationBehavior. In the Validate method, I've got
The other implemented methods
ApplyClientBehavior
,ApplyDispatchBehavior
andAddBindingParameters
are all empty.I have decorated one of my service operations with
[ServiceStatusValidation]
which is the class name of my custom behavior.When I start the service and navigate to the operation with this decoration, I do NOT get the exception I've thrown. SOAP UI shows nothing as returned in the response pane, and my consuming REST facade gives a generic 400 error with The exception message is 'The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error.'.
Any ideas? Should I be doing this logic in one of the other methods that I didn't implement instead of the
Validate
method?You would have to have a second service, that offered the same interface, same methods etc., that would all return that friendly message instead of a real result.
That might get a bit trickier when those service methods don't just return a string but a complex data object - where do you put that "friendly" message??
In reality I think this cannot really be done - since your services typically aren't "seen" by actual people, you cannot just put up an
app_offline.htm
file or anything like that.Try to have as little downtime as possible, by e.g. setting up your new version of the service on a new port and testing it there, until you're confident enough to switch over.
With WCF, it's mostly an exercise of updating / copying around the appropriate config, so your service should never really be unavailable for any extended period of time (hopefully!).
If you really must, what you could do, is just have a replacement service that will always throw a
FaultContract<ServiceDownForMaintenance>
- but then all the clients calling your service would have to know about this and they would have to handle this case and present an error or information message. Your service can't really provide that...