I have two applications: one in C#, the other in Java. I need a way to transfer data from the C# application in XML format to the Java application using some kind of service.
I have only worked with sockets before, but am looking for something less proprietary for future use with other applications. What other alternatives are there?
*Please note that the extent of my knowledge with working with sockets was a simple client/server written in java.
If both programs run on the same machine, you could of course also use files, but in general, this is how it goes down:
Create a webservice in C#, implementing a method that exposes your data.
Use the wsimport tool provided with the jdk, point it at the above created .wsdl file to generate java classes to use as a soap client.
Use generated classes to consume webservice.
(I see now you insist on XML. So forget about it)
These are completely distinct issues - it's like asking if I want to speak with you now, should we have a phone call in French or maybe mail correspondence in Mandarin. So it's:
Means of transferring data (S.A HTTP, or TCP, or whatever).
Some common structure of data.
Confusingly, both are regarded as 'protocols'.
Anyhow I'd say protobuf over HTTP is the most obvious and straight forward thing to use.
Related
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.
This question is a follow up on a previous asked question: link
I have to develop a Windows Service in .NET/C#. The service must be consumed by an application written in VB6. The service implements Quartz.NET to handle scheduled tasks and must implement listeners to be able to start functions that are initiated by the VB6 application.
The requirement for the VB6 team is to be able to use Winsock. Therefor I have to use sockets and listeners. The problem is that I have no experience with that, I'm more of a WCF guy.
I'm looking at the TcpListener class now to see if this will fit the requirement.
My first question: Will the VB6 team be able to consume the service if I implement the TcpListener class, keeping in mind the short comings of using VB6 (such as data structures and binary formatting)?
My second question: Let's say 3 functions must be available for the VB6 application, and 1 listener is created. What are the best practices for the implementation of this?
Once again: any advice is much appreciated!
Passing payloads as XML, textual Key/Value pairs, JSON, or other loose serialization formats can help future-proof your protocol. This allows you to use and even add new optional method arguments to the server end at will.
In addition to a "method" field you can have a "protocol version" field. When a breaking change is made (new required args, changes in existing arg types, etc.) you can use the version number to handle both old and new clients during a transition period - which might span years.
As far as providing message framing on top of the TCP stream goes you can use simple EOM delimiters of some sort or a message header containing a binary or text length prefix.
You might also consider Named Pipes. TransactNamedPipe() is fairly easy to call from a VB6 program. This takes care of the message-boundary issue for you - assuming you want an RPC-style protocol rather than async send/receive.
Or you might go all the way and use MSMQ. Private machine queues don't require extensive administration. But even though both VB6 and .Net have excellent MSMQ support most devs know little about it.
I am a c++ developer and need insight with current project...
I have a C# .net application that I want to securely connect to a mysql database
I have a sql database created and have created a "webservice" using php that I supposedly can connect to and through that it will access my sql database
but Need some insight into how to talk to this php code
Also would like to hear thoughts on this metholidgy ... is this best practices for doing this? (most secure, fastest, what about hundreds (thousands?) of users accessing a database will this hold up?)
My end result is to have this run on mobile platforms (android, ios) using Unity3D
I am trying to get the basic running using .net 3.5 c# so I understand it before I have to port it to mobile platform and the .net subset with unity
If someone would help me outside of the scope of answering these questions, I am always willing to pay to get this figured out
A great choice that would be very easy to implement in PHP and C#, as a bridge, would be Web Services built using JSON as the interchange format.
This looks like a good basic introduction for a JSON PHP Web Service.
This is another in C#.
With a neutral interchange format you should be able to connect the two components with ease.
I prefer to use JSON.NET and it works really well with JSON object serialization. Though JSON serialization is built into the core framework now (since .NET 3.5).
+1 on using JSON, but only if actually needed.
You can treat 'talking' to the php code as any other webservice. Create your api on the server side (ie. what the scripts do, what params they need), then forget the implementation when writing the client code.
Think about security. If you'll be exchanging sensitive information, you may want to encrypt it. So... SSL.
Do you have user-specific data? You may want some kind authentication.
One easy solution, if you're an optimist, may be to use a private salt and hash your parameters to make sure requests are coming from code you have distributed. However, this won't stop one user to pose as another.
As for scaling, it all depends on just how many calls you do, how many concurrent users you have etc., only you can estimate this stuff. Getting a cloud account would be good. Set up everything on one box at first. As traffic increases, move the database on a new node, then add a webserver, a master-slave setup, a load balancer..etc.
I think it's a nice approach, just be very careful with authentication and security. Performance shouldn't be an issue as long as you optimize the access to the database (performant queries, caching on the client and the service if necessary).
As for the web service consuming in C#, you should use service references for SOAP web services, or HttpWebRequest for REST web services.
For more information on the subject, this kind of architectures are called Service Oriented Architectures (SOA).
Can you give me some advice on how to best ensure that two applications (one in C#, the other in Java) will be compatible and efficient in exchanging data? Are there any gotchas that you have encountered?
The scenario is point to point, one host is a service provider and the other is a service consumer.
Have a look at protobuf data interchange format. A .NET implementation is also available.
JSON for descriptive data, and XML for general data types. If that is not efficient enough for you, you need to roll your own codecs to handle the byte ordering difference between C# and Java.
Rather than focus on a particular technology, the best advice I can give is spend time focusing on the interface between the two (whether that be a web service, a database, or something else entirely). If it is a web service, for example, focus on creating a clear WDSL document. Interface, interface, interface. For the most part, try to ignore the specific technologies on each end, outside of some prototyping to ensure both languages support your choices.
Also, outside of major roadblocks, don't focus on efficiency. Focus on clarity. You'll likely have two teams (i.e. different people) working on either end of this interface. Making sure they use it correctly is far more important than making things just a little faster.
If you have Java as a webserver, you can use Jax-WS ( https://jax-ws.dev.java.net/ ) to create webservices and WCF for .Net to connect to the Java Webserver..
You can use something like XML (which isn't always that efficient) or you need to come up with your own proprietary binary format (efficient but a lot more work). I'd start with XML and if bandwidth becomes a problem, you can always switch to a proprietary binary format.
Something like SOAP (Wikipedia) is supported by both C# and Java.
We use C#/VB.Net for our Web interfaces and Java for our thick client. We use XML and webservices to communicate between the database and application servers. It works very well.
Make sure that you use a well defined protocol in order to communicate the data, and write tests in order to ensure that the applications responds according to contract.
This is such a broad question but I'd recommend focusing on standards that apply to both platforms; XML or some other standard form of serialization, using REST for services if they need to interoperate.
If you use XML, you can actually externalize your data access as XPath statements which can be stored in a shared resource used by both applications. That's a start.
We are building a system that interacts with an external system over TCP/IP using the FIX Protocol. I've used WCF to communicate from client to server, where I had control over both client and server, but never to an external TCP/IP based system. Is this possible with WCF? If so, could the community provide links for me to get started and faced in the right direction?
Unfortunately I do not have much more information that what is supplied above, as we are still in the early early planning stages. What we know is that we have an external vendor whose system will communicate with our system over TCP/IP. We would like to use this as a learning opportunity and learn WCF.
Possible? Possibly yes, but it's going to take some work.
For starters, you will need to write a custom WCF Transport Channel that handles the specifics of your TCP/IP based protocols (i.e. you'll need to write all the socket handling code and hook that into the WCF channel model). This is because the TCP channel in WCF isn't for this kind of work, but uses a relatively proprietary and undocumented wire protocol.
I'm not familiar enough with FIX to say how complex it would be, but there are some gotchas when writing WCF channels and documentation in that area isn't great.
The second part you'll need to deal with is message encoding. To WCF, all messages are XML. That is, once a message is passed on to the WCF stack, it has to look like an XML infoset at runtime. FIX doesn't use XML (afaik), so you'll need to adapt it a bit.
There are two ways you can go around it:
The easy way: Assume the server/client will use a specific interface and format for the data, and have your channel do all the hard work of translating the FIX messages to/from that format. The simplest example of this would be to have your WCF code use a simple service contract with one method taking a string and then just encapsulating the FIX message string into the XML format that satisfies the data contract serializer for that contract. The user code would still need to deal with decoding the FIX format later, though.
Do all the hard work in a custom WCF MessageEncoder. It's a bit more complex, but potentially cleaner and more reusable (and you could do more complex things like better streaming and so on).
The big question though is whether this is worth it. What is your reasoning for wanting to use WCF for this? Leveraging the programming model? I think that's an important consideration, but also keep in mind that the abstractions that WCF provides come at a price. In particular, some aspects of WCF can be problematic if you have very real-time requirements, which I understand is common in the kind of financial environment you're looking at.
If that's the case, it may very well be that you'd be better served by skipping WCF and sticking a little closer to the metal. You'll need to do the socket work anyway, so that's something to consider there.
Hope this helps :)
I don't think it is possible, at least it won't be easy to set it up because you don't know the communication protocol of the other end, except for it's TCP and accept FIX tags.
Why don't you within WCF application open TCP connection a SOCKET. That should do the trick in a simpler manner.
I think so. I have a system that I almost got working that was supposed to do almost exactly that (WCF over HTTP from the internet). The server provider seemed to not want to allow it thought so you will need the right permissions on that end to make it work.
Up shot: I don't see why not.
Not really - Ms didn't make the TCP/IP connection handler to talk to non-WCF services, they assumed you'd write a Web Service to do that.
This is discussed here on SO.