Solutions for dynamic WCF client proxy in Silverlight? - c#

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");

Related

Dynamic WCF service coupling on IIS

I am trying to build a service mechanism which should be add-on based and communicating through a publish subscribe system. It must be based on WCF services.
What I have right now is a concept which I can't get to work so I decided to ask you because maybe I am going at this the wrong way (I only just started using WCF).
What I want to achieve is making a single core service with session persistency which can be extended by linking an unknown number of add-on services. I want to set up the publish subscribe system at runtime, not at buildtime, so the core-service should be able to detect what add-on services are available (using the web.config?) and then bind them to the message bus.
From the front end (ASP classic) it must be possible to access any .svc file but, maintaining session, each .svc file must be connected to the message bus.
All is hosted in a single IIS active directory.
Can you give me some hints as to where to look?
I am especially interesed in:
WCF dynamic discovery
WCF to WCF communication on the same host (in the same active directory even)
Thanks in advance, hope you can help!
Update
Thanks for your answers, I'll read up at the links you send me. I'll post my final concept solution here in due time for future reference.
My 2 cents about Publish subscribe mechanism using WCF - WCF is not inherently built for pub/sub mechanism. It is built for Request/Response model of communication. Have a look at the NService Bus for pub/sub here
Talking about Add on services on top of core service, I am not able to get What you want exactly ? Is it the Routing service which you want ? WCF 4 now provides routing service For more information look here The link also talks in detail about the discovery mechanism in WCF 4.
Also have a look the Agatha framework which also have single WCF service and no. of request handlers where in the framework will decide which request handler to call based on each request.
Search for Agatha - Davy brion for more information
I was having a similar problem since I have one common WCF service but the implementation depends on the user's role so it was kind of difficult to do that at runtime.
I found this tutorial on the matter which runs great for my propouses: http://blog.micic.ch/net/dynamic-iis-hosted-wcf-service
I have tested in my env and is very powerful technique. Hope that helps you as well. Cheers.

Looking for a Best Practice regarding Webservices between .Net and Cocoa

I'm planning a project which will consist of a Windows Server Application programmed in .Net/C# and Clients programmed in Silverlight/C#, Windows Forms/C# and a MacClient programmed in Cocoa. My Question is, which Webservice technology will be the best for the communication between the Clients and the Server and is the easiest to program in all of those technologies? I've no experience in Webservices and since Time is running short I hope to get some opinions of developers who worked in such a kind of heterogeneous project.
On the back end, you will definitely want to run Windows Communication Foundation, using the WSHttpBinding or the BasicHttpBinding depending on your needs.
This will make it easier to have Windows Forms and Silverlight clients.
Also, because using WCF with those bindings conforms to established standards, you should be able to access the services from almost any other environment - there should be tools that you can just point it to your metadata endpoint and it will generate proxies for you.
Another option is to use WCF to create a REST service (with JSON encoding most likely). WCF does help you a little bit here, but if this is the design you want to use, then you will want to look at ASP.NET MVC on the back end as well, as it makes creating these kind of services very, very easy.
However, when using REST services, there isn't a service description through something like WSDL, so you will have to generate the proxies to call your services by hand (at least, in environments outside of .NET).
The current technology used to develop web services on .NET is WCF. For interoperability with non .NET clients you should consider using basicHttpBinding endpoint. You could even expose multiple endpoints with different bindings, for example expose interoperable endpoint for non .NET clients and some fast binding for .NET clients. Here's a nice article on MSDN covering the performance of the different bindings. Given those keywords you might checkout the tutorials.

Can I use WCF in this case?

We have a third party application that provied its web services to us by ASMX and it is created at the time of .NET 1.1
in the old days we were using VB 6.0 and connected to it by a PocketSOAP, etc...
bt now we want to replace the VB 6.0 with C# 3.5 WinApps and still use that third party web services.
so I wish to know what are my options for doing this? which one do you recommend and which one has a faster learning curve?
Thanks All.
From what I understand, you want to use consume the old web service only and want to replace your client application which was done using VB6.0. You dont have to use WCF here, you can create your client application using Win Forms/WPF. WCF is for providing service and in your case you want a client application.
My opinion will be to use WPF or .net winforms.
I'm not sure what you mean by "which one", what is the other option you're referring to?
But yes, you can use WCF as a client to an .asmx web service.
Just add a service reference like you would to a WCF service. It will use the WSDL to generate a client proxy.
You can use the BasicHttpBinding in WCF to interoperate with legacy services.

Call .Net 3.5 WCF service from .Net 2.0 Standard ASMX Web Service Client

I created a service that is hosted on a server that has .Net 3.5 installed and I need to call this service from a client that only has .Net 2.0 installed.
Is there a way I can do this?
If your WCF service exposes an endpoint using basicHttpBinding, then it should be possible for the .NET 2.0 client to consume it. As Marc said, "no problem".
Yes you can do it. There are some caveats, however:
You have to use protocols that match. The standard .NET 2.0 libraries don't support many secure web service features; in fact, you're pretty much stuck with using only basicHttpBinding on the WCF service if you want to be consumed by a default install of .NET 2.0. That is a severe limitation in many enterprise scenarios. However, it may be all you need.
If you need more security but are still using .NET 2.0, there are alternatives. Again, your WCF service must accommodate your .NET 2.0 client, but your .NET 2.0 client will also need to take advantage of an external library. Specifically, you'll need the Web Service Enhancements put out by Microsoft. Keep in mind, however, that these libraries implement a beta version of some SOAP protocols, while WCF (the successor to WSE in many ways) implements the standards by default. Since there were some breaking changes in the protocols (particularly WS-Addressing), you'll have to offer a customBinding endpoint on your WCF service to accommodate.
Unfortunately, I can't tell you which you'll use, as it'll depend on which protocol you want to accommodate on the service, but most of your problems will be solved by changing the messageVersion of the textMessageEncoding for the custom binding. This is not the best scenario, but it could buy you something if you're trying to integrate a client.
Bottom line, there's a lot of work to get a .NET 2.0 client to talk to a WCF service for anything other than basicHttpBinding. In many cases, basicHttpBinding may be enough. For many enterprise scenarios, it will not. I can't speak as to which will help you or not, but it is possible to get it to work -- I've done it successfully.
But it's a big pain. Look for an alternative if you can.
Yes of course - the service being hosted on .NET 3.5 doesn't require the same version of the .NET framework on the client. Heck - you can even call such a service from Java or PHP! That's the whole POINT of Service Oriented Architecture! :-)
You need to define your service contract (what's the service called; what methods are available to be called on it) and you need to decide how to host it, e.g. at what address can you call this service, and what parameters are required (e.g. HTTP vs. TCP, secured or not secured etc.) - that's a lot of work, even in WCF.
Here are three introductory articles for WCF - check them out!
MSDN
CodeProject
Dennis van der Stelt's Blog
But calling that service from a .NET 2.0 client is ABSOLUTELY no problem!
Marc

Service Host Resolving - C# Equivalent to RMI Registry?

I'm taking a Masters capstone course early and doing my project in C# while everyone else is doing theirs in Java. The project has 4 services and requires a name server that maps service names to sockets. The instructor is suggesting that the students use RMI to build this registry. Since I'm not very familiar with Java, and the instructor is not very familiar with .NET, we weren't able to come up with an equivalent in C#. Anyone out there aware of one?
Update:
I'm looking for a way to discover a WCF service without explicitly knowing its socket.
Update 2:
I will be demoing the project on my XP laptop using VS 2008/WebDev server.
You can use the UDDI server that comes with Windows Server 2K3/8. This will give you discovery of your services. Other than that you would need a 3rd party package or roll your own.
RMI Registery in java works as a container where you can lookup services by a key. This mechanism is similar to resolving services/objects via ServiceLocator (e.g. ServiceLocator pattern) where you use a dependency injection engine, and ask it to resolve an instance of the service (i.e. by a known name, by interface, etc.):
IMyService service = ServiceLocator.Resolve<IMyService>();
or
IMyService service = (IMyService)ServiceLocator.Resolve(typeof(IMyservice));
WCF works only in a single service vs. single service host fashion, meaning each single service requires a separate service host. You can write a service container that aggregates the service hosts, opens the port, and registers them in DI container, and later simply ask for an instance of the service as mentioned above.
I am no expert on Java Remoting.
I think what you are looking for is called in WCF terms Service Endpoint.
This can be done either in a config file or via code .
For an overview on WCF I would refer you to this link:Windows Communication Foundation Architecture
Read about TCP Port Sharing, new technology in Windows Server 2008, it could helps you

Categories