We have a background service, which has the single purpose of getting recent data from a server.
Now the server should be an OPC-UA server. Unfortunaly, the SDKs and examples I found to connect to this are limited/only explained in ways that are heavily integrated with a classic windows forms application. Up to the point where its impossible to separate GUI from business logic.
At this point I'm wondering if we are misusing the client functionality and should opt for a different way?
Ideally I'd like to wrap the whole OPC-UA Logic inside a class library and just call GetData(), is that impossible?
You are probably referring to the "SDK" provided by the OPC Foundation - but you have not stated that explicitly in your question; in fact, you used the term "SDKs", in plural. There certainly are also commercial SDKs which might be better in this respect.
Here is one (QuickOPC), together with one-liner example of reading the OPC UA data: https://www.opclabs.com/products/quickopc/opc-specifications/unified-architecture/generic-data . Disclaimer: This is a self-promotion.
You might find Tutorials for Client development, specifically Console Client useful. This is a much better SDK than the one from the OPC Foundation. You will find full C# samples including a console client application (no GUI).
You might want to re-evalute your needs for
Ideally I'd like to wrap the whole OPC-UA Logic inside a class library and just call GetData(), is that impossible?
It is totally possible, but with OPC-UA, you have to keep in mind that it is recommended to get data using a subscription model (Monitored Items) instead of performing an explicit Read for a value (unless you just want to read an attribute once). So, I would make sure that however you are building your client-side class makes sense for the needs of your application.
Related
Background:
I have an old vb6 application that I really need to get out of my life. I love coding in c# and want to make an application to replace the old vb6 application.
The vb6 app has a component app that is installed via IIS and that the main GUI vb6 app connects to for various purposes. The reason the COM app/components exist are so that everything done is coming from the same source.
Ex: I'm working remotely and need to connect to an FTP server that is only accessible from my works network. The main GUI app connects to the COM object, issues a command and then that set of components creates the FTP connection from my work network/ip (instead of my home network/ip).
Question:
In replacing this old application GUI and COM object, what is the best approach in c#? Should I still use the old Component Services that I hate so much? Or is there a newer, better way of going about this same task?
There is nothing special about using FTP that would require COM (and certainly writing a GUI in C# does not require COM either).
If I were doing it:
WPF GUI (Future proof for when WinForms is gone... and gives you a leg up with WinRT which also supports XAML).
Nuget in an FTP library, like this one: https://www.nuget.org/packages/Ftp.dll/
Make sure you separate your GUI from your back-end communications through appropriate interfaces/patterns so you can replace things easily and more "future-proof" your application.
Edit:
So, what you're really after is: How can I have a GUI front end that talks to a back end via various means?
So, there's lots of answers to that, and it basically boils down to, either: don't do that, "pick a lane and stick to it", or "Use WCF".
WCF (Windows Communication Framework https://learn.microsoft.com/en-us/dotnet/framework/wcf/whats-wcf ) is a back-end server side technology that supports multiple communication protocols simultaneously, but generally allows you to interact between client and server. SOAP was originally the popular choice, but it also supports Remoting (which you alluded to), you can send attachments via DIME which is then like FTP, or you can roll-your-own and do anything you want (e.g. using Capn Proto (https://capnproto.org/) to send binary messages).
Alternately, if you can get away from trying to do everything, you may want to look into REST instead which is supported by Web API (https://msdn.microsoft.com/en-us/library/dn448365(v=vs.118).aspx ). This will allow you to send lightweight data back and forth, and is, typically, "the way it's done" these days.
Good luck!
is it possible to invoke function which is written in Java using WCF or any class application written in C# .net
Can it be possible by using webOrb..
i can't find enough information about Java to .Net remoting..
If you want to communicate between C# and Java you have a couple of options.
The cleanest: Build a service.
This assumes you have access to the source code of both your C# component and your Java component. In the case that you want to call a method within Java, you can build a service that allows a connection from your C# client, to your Java service, and the service then executes the desired functionality, and returns a value back to the C# client. Some easy ways to do this is by building a RESTful service or using Thrift. I recommend you choose a solution similar to this one.
The most complex: Corba
Corba is a standard defined to communicate amongst different computer languages. Most mature languages have support for it, but it is a bit unusual, and the use of it has declined in favor of building service. This also assumes access to both source codes.
You'd have to independently look for the information regarding how to use Corba on both Java and C#. I would really advice against this.
The dirtiest but quickest: Execute as process and parse output
I really do NOT recommend you to do it this way unless you really have no choice. This would entail executing a Java program from within C#. This is only a good choice when you have no other option, because all you have is an executable. If that were the case, you can use the Process class to execute the external program, sending it parameters, and then reading the output. See the example mentioned here:
How do I start a process from C#?
This has many downsides though, as you'll have to think of every exceptional cause, determine the output for those cases, and then determine how to parse that output. If the program has any level of complexity, before you know it, you'll end up with hard to maintain code.
Conclusion: Build a Service
That's probably your best bet. Build a service that exposes an API that the C# client can call on.
We are using JCOBridge package: it is able to create a bidirectional invocation of Java API from C# (.NET Core/6/Framework).
The templates available on Templates was our good starting point for the needs we had. We reach the goal in few lines of code.
UPDATE 2022: the JNet project on GitHub can be used as a starting point. Another project is KNet, hosted on GitHub and based on JNet, that is a gateway for Apache Kafka Java API.
Yesterday I asked about what technology should I use to create dynamic web content here:
PHP, AJAX and Java
The suggested methods were JSP, JQuery, etc. But I thought maybe because I'm a .Net developer and I don't have any experience in web development but I have experience in WPF and C#, maybe I should go with Silverlight but the main problem here would be how can I communicate with the core part of my system which is implemented in Java?
So the main question would be: What is the best [and easiest to learn] method to send a piece of data to the Java part, get the result and use it in silverlight? A tutorial or simple example would be nice.
Thanks a lot in advance.
You should use Java Web Services as stated. Use WCF to invoke the Java WS by adding a Service Reference in Visual Studio by its url, then use the proxy classes generated automatically (located in Reference.cs) to invoke the WS. This is easy but remember SilverLight WS invocations are always asynchronous, so you must cath the OnCompleted event to get the results of the invocation. WS are slow but if the machines are in the same LAN, invocation could take a few milliseconds.
I think pipes are not your solution as SilverLight executes in a Sandbox and have many restrictions on what you can do.
This will depend on many factors, however a relatively easy approach would be to use Java Web Services. On the .NET side, WSDL will be picked up and transformed into proxy class by WSDL.exe from the Windows SDK. If, however, these two systems are on the same server (and intend on staying this way), you may decide to use pipes.
I've started with Flex recently, I've noticed that some plugin for Visual Studio exist, instead of buying a licence for another program (Flex Builder).
I was wondering how I could manage to remotely connect to my database with a Flash/Flex application with the help of C#/Asp.Net.
If I've correctly understood what I've read in the last few days, there is basically no way to 'query' to a database with Flex 3. So I suppose there is another way by using a webservice in C# on the database server that would respond to the Http query from Flex.
Am I right or totally of the track? If you have any other thoughts about this, please share.
I prefer (and recommend) using Webservices for the communication between Flex and C#. It's easy to use, and they both support serialization, so you can easily transfer Strong-Typed Objects. More on Flex and .NET can be found at http://www.adobe.com/devnet/flex/flex_net.html
Alternatively, you could consider using WebORB. This program functions as a gateway between and Flex, and enables you to use the Flash RemoteObject API for the communication to C#. More on this can be found at http://www.adobe.com/devnet/flex/articles/flextodotnet_remoteobject.html.
You really should consider using FluorineFx.
It takes about 5 minutes to set up an will allow Flex to call your methods like a service. You can then pass classes back and forth from .NET to Flex and back.
It's also the standard form of communication by Adobe, it's free and it's super fast.
Your understanding is correct. Flex is intended for developing client-side applications, and communication with a database is done through a server-side application.
Pretty much the same as building a JavaScript application. Though, Flex has several additional options for communicating with the backend. Webservices are great in a lot of cases, but the other options are worth looking into.
Here's a pretty happening article on the topic, if you haven't already seen it.
http://www.dehats.com/drupal/?q=node/33
I'm looking for a small and fast library implementing an HTTP server in .NET
My general requirements are:
Supports multiple simultaneous connections
Only needs to support static content (no server side processing)
HTTP only, HTTPS not needed
Preferably be able to serve a page from an in memory source. I want to integrate it into another app to be able to make changing data available via a browser, but I don't want to have to write it to a file on disk first. For example, just pass it a C# string to use as the current page content.
Preferably open source so I can modify it if needed
Definitely needs to be free... it's for a personal project with no budget other than my own time. I also want to be able to release the final product that would use this library freely (even if that means complying to the particular OSS license of that library.
Edit: To clarify some more, what I need can be REALLY simple. I need to be able to serve essentially 2 documents, which I would like to be served directly from memory. And that's it. Yes, I could write my own, but I wanted to make sure I wasn't doing something that was already available.
Use Cassini.
Free, Open Source.
It would take trivial hacking to serve from memory.
Well, how complicated of a HTTP server do you need? .NET 2.0 has the HttpListener Class which you can use to roll your own basic library. Since this is for a personal project and you are willing to invest the time, it would also make for a good learning experience as you you would get to learn how to work with the class. Additionally, according to the MSDN documentation, it has an asynchronous mode that gives each request its own thread.
Getting a basic HTTP server with the class up and running isn't too difficult either, you should be able to get it done in only a couple hundred lines of code.
Check out Kayak.
Note: kayak doesn't seem to be maintained anymore - though it deserves to be so
LightHTTP is an open-source library I've created that does exactly what you need.
It can be used in testing and mocking, or other scenarios where a lightweight HTTP server is preferred.
It works asynchronously.
Supports simultaneous connections.
It can serve anyway you'd need, since it's based on HttpListener.