I have a WPF application, that I want to port to Linux/Mac. The most logic way seems to split the application in two parts: client and server, and use Silverlight for the client UI, and run the server-part (as an invisible console-app) in Mono.
But what's the best way to let those two parts communicate? Silverlight 4 supports COM interop, but I cant use that because it will fail in Moonlight. So I was thinking about socket-connection to localhost, and use JSON or something similar. Or is there a better way which doesn't require me to write dozens of wrappers for all the function contained in the server-dll? Because communication will be between Mono<>Moonlight, maybe i can use something similar as COM interop that is cross-platform?
maybe you can consider to use Eneter Messaging Framework.
It allows to implement the communication between Silverlight and standalone application based on Tcp. The low level communication is hiden and the framework is very easy to use.
You can see the following example:
http://eneter.blogspot.com/2010/07/silverlight-interprocess-communicatin.html
You're on the right track.
You should create a web server application and the Silverlight app would communicate with it over http://localhost via REST or SOAP.
Joshua - I'm a bit confused (and I don't mean that in a negative way). If the app runs on the users machine then isn't there's no "server" to connect with?
What's the nature of the server-side components? - what do they do? Can't you just run the whole thing from within SilverLight?
SilverLight is providing the runtime host for .Net, in that sense it can contain your whole app - which can still be layered like a "conventional" web-based solution, so you can still have separate assembilies for Business Logic, etc.
Related
We are getting in the design phase of using MvvmCross for our application platform and we are trying to figure out if we can use the MvvmCross Plugin to broadcast messages between multiple MvvmCross applications? These applications will be running on the same machine in parallel, and on an internal network.
I did consider using RabbitMQ for this but found out that you cannot add RabbitMQ to a Portable Class Library Project. So that's out of the question.
I watched this video : https://www.youtube.com/watch?v=HQdvrWWzkIk and the speaker says the Messenger can be used within an application, but I would like to know if it can enable communication between different applications.
Any help would be greatly appreciated.
My guess is that it probably creates an instance and uses that for communication, making it less ideal (if possible) for across applications.
You should be able to create a program that listens to a port and redirects accordingly, creating the same functionality though.
What I ended up doing was creating a Windows Service Hosted, WCF service (NET TCP) which enabled me to do cross process communication. Then when a process received a message via WCF, it relayed the message internally using the MVVMCross Messenger.
Seems to work pretty well so far, although it's only been used with 3 processes. So not sure about the scalability of this solution.
I am working on a project requiring communication between the Presentation layer (MVVM based client) and the Business layer. The application is to be installed on a single machine, and as such could have been executed using a .net remoting based approach. However, I have been suggested to use WCF since .net remoting is deprecated and WCF is the way to go.
So I implemented WCF Service as a WCF library project. I added a service reference (using visual studio tool by discovering services in the solution), which was successfully added on the client side. All works well, since during debug session visual studio launches the service library and the client can connect to it successfully.
Now Since the client and service host will be installed on same machine, I was thinking of using named pipes transport and self hosting for the WCF service. Here is where this gets very confusing to me:-
Since the MVVM client is the "main" app (since it is the application frontend), the client will be launched first. I am unable to come up with a solution to launch the service host "on-demand" when the client needs the same.
What are the solution I can use to do what I require for 1? I am not sure of using a continuous service through windows service for something that will be required "on-demand".
Please suggest clean approach to implement a way to launch "on-demand" service.
Thanks in advance.
I'm not quite following you here. MVVM is cake and really doesn't have anything to do with your problem. Using a servicebased architecture is a must today, I just want to smack every old guy/gal sticking to direct SQL on the client side, and don't see the dangers with that.
Well anyhow, you may solve this different ways. WCF is BIG, to big in my opinion. One way to use it, common on small applications like apps(WP8.1, 8.1 apps++), is just to connect, call the method you need and the close the connection. Case solved, given that I understand your needs. The otherway is to keep the session alive for each service... (ugh, loadbalancing etc).
I've been working on large LOB applications the last 4 years my self, what I can tell, is that if I were in charge, I would have done it very differently. For once I would used JSON endpoints with SSL over HTTP, and the json.net serializer. The datacontract serializer which is the default in WCF, is not good news at all. JSON allows easy communication with JavaScript based applications, and the serializer doesn't break like porcelain as the datacontract serializer does. Address/baseaddress may be stored in your config file, so it may be changed upon deployment(you probably have many servers, for different environments).
This is a really old post covering the subject(supporting SOAP aside JSON); REST / SOAP endpoints for a WCF service
Don't be stupid and just call your services directly now! Use the interface(Wrap if necessary) and feed it to your viewmodels for proper TDD! It will also allow you to completely replace WCF with another form of communication.
There also are alternatives to WCF.
IIS? Hosting WCF in IIS rather than a proper service? No way, flush that idea down the waterloo ;) (internal joke)
EDIT:
BTW: Your service must ofc already be running for your client to connect to it! Or nothing will be listening to your configured port. If you are selfhosting, you can use parameters to start in debug mode, that is start your service like a regular application you may debug. In Program.cs;
if (args.Length > 0 && String.Equals(args[0],"debugmode", StringComparison.OrdinalIgnoreCase)
{
Service1.Create(); // Debugging!
}
else
{
// Hosting
service = new Service1{ServiceName="YourService"};
ServiceBase.Run(new ServiceBase[] {service};);
}
Hope it helps,
Cheers,
Stian
So, i'm building my first SL application.
I tried to use the MVVM approach, and I think that's the way for me.
Basically, it's a simple application which shows data to the user, the data source is local (maybe in the future will be centric, but right now this is not the case), and the data should be retrieved by:
A. Calling file system's reading
and
B. Method calls from External DLLs
So, as I said, I started to work with MVVM (used this tutorial). I have 3 components: the service, the SL application and the project that host the SL app (excuse me if i'm not using the exact proffecional terms...).
My question is: Do you think that I've chose the right design? if so, is there any way not using IIS to host the service or is it a must? (I don't want to spend time on adminastrative tasks on clients' computers), because as I said, the data is local at the moment and IIS feels unnecessary.
I'll appriciate every comment on this. Thanks!
EDIT:
I'll try to simplify my question: I need my SL app to communicate with some kind of service - that will be able to take requests and reply back to the app.
This service suppose to be able to use .net dlls, and this service should be locally on each client run the app.
EDIT:
I noticed the Self host option.
Does anyone has any experience with it?
If your question is about: You having access to a database server somewhere, you should try WCF RIA Services. This will allow you to create service for each entity and the service will get included into your host project or you can even create a WCF RIA library.
As suppose to your MVVM pattern. I prefer splitting my Views from my ViewModels In different projects. I like to see them as a seperate layer.
Actually using ria services may mean that you have a number of services which apply to one user, but yes they are specific to the user. Which file system would you be attempting to access? The client or the server?
I finally decided to go with XBAP(WPF XAML Browser Application).
It suited perfectly to my requirements:
1. no deployment issues - just press a link, and .net enviroment will do the rest (downloading the needed assemblies, install them and finally run the app)
2. it's hosted on a browser
3. no IIS is needed!! it's a client-only application
I am working on an in-house, iOS app that will need read-only access to a SQL Server with multiple databases. I know the stock answer here is "write some web services", but I'd like a solution that is self-contained. Is there any way to directly connect to a SQL Server database from an iOS application? I'm thinking something like a basic ODBC connection.
I've seen a lot of users asking this question, but very few answers other than "write a web service." Is that really the only way?
A web service is indeed the only way, but Red Gate's written one you can reuse:
http://www.mobilefoo.com/iSqlServerSDK.html
http://labs.red-gate.com/Tools/Details/iSqlSDK
It's not officially released yet, just in beta, so keep in mind that features & prices may change.
Actually the easiest way is to create a MVC 3 or 4 asp.net web application. call the web methods. You don't need any API to pay for.
I use SBJson to serialize domain object and then send the objects as serialized jSOn to MVC 3. It's super easy to do. I even send images with base64, so it's .net compatible.
See my blog post with sample code:
http://nickturner.wordpress.com/2012/10/09/107/
So, after much searching and trial and error, unfortunately the best (only?) way I've found is indeed using Web Services.
Fortunately, Linq to SQL makes the WCF-creation-side incredibly easy. Once I got someone at work to walk me through setting up a Windows web server and adding the web service (and buying access to an online web server), the Windows side was up and ready to go.
I'm still working through all of the syntax stuff on the SOAP interaction side, but keeping my different methods somewhat similar in structure allows me to tinker a little until it works. By this time, I think I've gotten it to work pretty well.
So, both answers I got back were (disappointingly) correct. The only way to interact is through a Web Service. Even the 3rd party solutions they mentioned were really just convenient wrappers around the same type of technology. As it turns out, I'd rather have finer control over the process.
One word of advice: Get a real, external web server. I tried doing this on a non-Server Windows VM on my iMac/MacBook Pro, and it was like pulling teeth! Once I actually got access to an external, full, stand-alone web server, the process was much more streamlined and easy. Do yourself a favor and take that headache out of the equation!
There was a SQL ISAPI extension as part of SQLXML, but I think it has been deprecated: http://msdn.microsoft.com/en-us/library/aa226559%28v=SQL.80%29.aspx
This was effectively a pre-built, and relatively open, web service - so I'm not sure this counts as a direct connection.
You could also check out http://odbcrouter.com/Main
I am trying to work on a home project so I can get some practice working on WPF & WCF applications. Can anyone give out suggestions on a sample WPF and or WCF applications that I can develop?
A project I was thinking about was to help regulate my teenage son's internet usage.
Windows has a UI-based tool to control logon times. A WPF front-end would be nice to duplicate or improve on that tool, but use it to set network usage times. This way, kids could do school work (not prohibited from logging on their computer) but not be distracted by facebook.
The WCF portion would be a WCF service on your computer and WCF client on the kids' computers. The kids' computers would periodically check for restriction updates. If network access is current OFF, then the client (on the kids' computer) would turn off the network adapters (both ethernet and Wifi), turn them on every few minutes to check for updates, then turn them off again.
Just define a data contract for whatever structure/class you want to represent usage, and the service would have an operation contract with a single call, like:
[ServiceContract]
interface INetworkControl
{
[OperationContract]
NetworkRestriction GetNetworkRestriction();
}
Maybe it would need more; that would be up to you (i.e., pass the computer name as a parameter, or perhaps logged on user if you wanted to control by user, who knows).
Maybe a peer to peer program ?
Not sure...I learned the 2 technologies by writing a facebook API based on WCF and writing a WPF frontend to browse the albums of my friends. My reasoning was that if WCF can do form-encoded POSTs with bare XML responses then it should be up for a lot of things.
I have bought an excellent program/tutorial here :
http://www.dofactory.com/Framework/Framework.aspx
I includes a program where WCF services are consumed by WPF (as well as by Windows Forms and a ASP.NET website).
It's about design patterns basically, but using services as datasupplier is a design pattern too of course.
(for the record : I really am not advertising for this company :-))
I think this might give you plenty ideas for your own programs, and if the aim is getting to know both technologies, it would be an excellent choice.