Now I'm refactoring old WCF and I need redirect some old WCF service requests to new WCF service.
What I do is intercept per old WCF service call use class implement IOperationInvoker. But I not sure how to set the outsputs in the invoke signature as below.
object Invoke(object instance, object[] inputs, out object[] outputs);
Can anyone give me some suggestion?
you can use Routing Service to distribute old request to the new one(filter by action,endpoint and so on), learn more from MSDN about Routing Service.
For my points, it's high degree of coupling if you handle this situation, you should also edit you code and compile again if you need more restructure in the future.
for Routing Service, just update the config file, no change in the old project.
Related
i have one doubt in Web Service / WCF
i'm creating the service and it's having 10 methods respectively
test1() , Program1(int age),Describe1(), DisplayAge(string name),,SimilarInterest(),ServiceCall(), Hide(), Difference(), WebService() and Help()
now after hosting this service in asmx only the below methods should display. others should not need to display.
DisplayAge(string name),,SimilarInterest(),ServiceCall() only these three should display when i call the http://URL.asmx?wsdl
the other 7 methods should not need to display in asmx wsdl file .how to do that?
As far as I know, in XML Web Service(ASMX), this should not work if you want the service to be both invoked and not shown in the WSDL. Either using private decorated methods or removing the [WebMethod] attribute causes the method to no longer be invoked. If in WCF we can implement authentication, authorization that individual methods cannot be invoked, or simply not expose metadata. But we cannot hide the specified method (but can be called by the outside world).
https://social.msdn.microsoft.com/Forums/en-US/533e0361-e9e0-400b-a7b2-f098a9ef3e75/how-to-prevent-web-method-from-showing-on-service-description-page?forum=asmxandxml
Feel free to let me know if there is anything I can help with.
I have around 6 WCF services that I want to host in an MVC application, routing requests to /services/foo to WcfFooService and /services/bar to WcfBarService
I can accomplish IoC with StructureMap within the services and inject my constructor dependencies by using the example that Jimmy Bogard blogged about here:
Jimmy's article is great, but I'm trying to extend it to work with multiple services hosted within the same MVC application. Essentially, the part at the bottom is the part that is causing me a few headaches:
public class StructureMapServiceHostFactory : ServiceHostFactory
{
public StructureMapServiceHostFactory()
{
ObjectFactory.Initialize(x => x.AddRegistry<FooRegistry>());
//var iTriedThisToo = ObjectFactory.Container;
//container.Configure(x => x.[etc]);
}
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
return new StructureMapServiceHost(serviceType, baseAddresses);
}
}
With a single WCF service - routing MVC requests to a specific url via the StructureMapServiceHostFactory shown above works brilliantly - but - If (for example) I create a StructureMapServiceHostFactory2 for the /services/bar call, to allow for a different Registry to be used, when the MVC app spins up, it appears to call each factory in turn as it runs through RouteConfig.cs and adds the routes, so ultimately I don't get configured instances that the first ServiceHostFactory should provide.
It doesn't make a difference if I call Initialize(); or attempt to grab the Container property and call Configure on it, either.
Am I on a hiding to nothing with this? The major reason for requiring registry isolation is due to different NHibernate configuration, but I could configure Named instances of SessionFactory and Session for NHibernate purposes and then use a single registry to get around this. In my mind I wanted the WCF service and MVC-hosting to be capable of using their own IoC containers in isolation, which is why I went down this route.
Is there any way that I can accomplish this?
Ok, so it would appear the only person capable of answering this was me, by virtue of a re-think and 're-architecting' the solution so that the problem doesn't exist in the first place.
I now have a capable way of hosting these services and maintaining IoC with StructureMap neatly per service, without any conflicting concerns.
If you find yourself in a similar position with SOA taking over (SOATO?) - taking a step back is a good start ;)
So, I'd like to create a behavior that I can apply to my WCF services to return a "dashboard" of sorts. By applying the behavior, I could say goto http://localhost/MyService/MyService.svc/dashboard and get returned a list of statistics for the server that I'm interested in.
I'm not sure where to hook in and override the default service page, there must be an extension point, I'm just not sure where to look. Any thoughts?
EDIT: I've seen ways to do this using HttpGet and Message, but this causes me to modify my existing services. I want a behavior that I can apply across to any service at the configuration level, so that I do not have to modify the services whatsoever.
I currently have something like this for my route table. Is there a nicer way to handle versioning in WCF Web API or conventional WCF?
RouteTable.Routes.MapServiceRoute<Service1>("1.0/Route1", Config1);
RouteTable.Routes.MapServiceRoute<Service2>("1.0/Route2", Config2);
RouteTable.Routes.MapServiceRoute<Service3>("1.0/Route3", Config3);
RouteTable.Routes.MapServiceRoute<Service4>("1.0/Route4", Config4);
You could do that, but it is very protocol-bound, in this case HTTP. I wonder if there is a way to do that without worrying so much about protocols? Ideally we only want to do it once and not for each transport out there. Luckily there is a way, let me explain.
At the end of the day, your WCF internals should be protocol agnostic. By that I mean by the time a method is invoked on your service, we should not care whether it came by REST, TCP, HTTP or named pipes.
In WCF this is pretty easy and so is versioning. With versioning we can learn much about .NET interface versioning particularly when it has nothing to do with WCF. The idea is that your service should realize:
interface ISomething1 { ... }
Later when a new method or changes are required you should:
interface ISomething2 : ISomething1 { void SomethingNew (...) }
It's then a simple matter to publish your service with 2 endpoints in config, one pointing to ISomething1 and the other to ISomething2.
I'll be more specific.
Lets say I have a contract defined for my WCF service. And I have two different WCF clients which reference to this service : "ClientA" and "ClientB".
Now , lets say I want to add an operation (method) to my service which only "ClientB" will use , Lets say I added this operation to the contract and "ClientB" updated its reference and we're all happy. Does clientA also need to update it's reference even though it is not using the new operation?
The client only needs to update his reference, if it's going to use the new Operation contract.
Check out this article: Versioning WCF Contracts
No, WCF web references are generated by the IDE very similarly to references to ASMX or other web services, which means that it breaks things down into a method inventory, such that the client calling code operates as though it were invoking a remote API. Therefore, if only new stuff that does not alter the expected existing functionality is added, then old clients do not need to update.