6

I have a C# form application that connects to a electronic device using the serial port. The class "'SerialCommunicationManager'" hooks up to the serial port on application startup and handles the dirty business of talkning to the device.

What I would like is to expose the following methods.

  • Write()
  • SerialDataReceived event
  • SerialDataTransmitted event

Primarily a local website running on the same machine is the one I want to expose the methods for, but in the future I imagine the need for external applications as well.

What is the easiest way to expose the functionality?

  • TCPIP client server?
  • Web service? (Can I create a web service inside a WinForm?)
  • other?

Big thanks

//David

enter image description here

2
  • I don't understand the context; you start with Windows Forms and end with websites. I don't get this.
    – Uwe Keim
    Sep 4, 2011 at 7:28
  • The Form application is connected to a electronic device. I want other applications (such as a website) to be able to see the status of the device as well as sending commands to it. The big question is: How do I allow other applications to talk to the device.
    – David
    Sep 4, 2011 at 7:50

3 Answers 3

4

I would recommend self-hosting a WCF Service. This provides you a huge amount of flexibility in terms of how you serve and expose this information, including being able to change the method by which its served via configuration.

1

It seems to me, that if you would like to do it properly, you should break apart your forms app, and create:

  • a service that handles serial comm and has an API exposed through remoting
  • a Forms app that uses the API and makes a way with the service

Then, depending on the locality of your web site, if it will remain local (or near local - LAN):

  • web site should use remoting to call the service

else, if you plan to have multiple web sites:

  • web service hosted inside the IIS that will wrap remoting API
  • web site that will use web service

However, if it is too much work to do - just use remoting and expose needed methods to the web site.

1

In a recent project we did the following:

  • Write a Console application (or Windows Service, depending on your needs) that communicates with the electronic device.
  • Make the Console application host a .NET 4 WCF service.
  • Write a .NET 2 Windows Forms application to communicate through Web Services with the console application.

In this context, I could imagine the website you are mentioning to also use Web Services (WSDL) to communicate with the Console application.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.