Tip WCF service library in self-hosted console server, and test client

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,799
Location
Norway
Programming Experience
10+
This is basically an update of an old Remoting example I posted here 10 years ago, this example does the same with WCF.

This VS 2015 solution contains three projects, configured as multi-startup:
  • WCF Service Library, includes the interface and implementation for one method, GetScreen, that takes screenshot of desktop and return it as a Stream.
  • Server, a Console application that is self-hosting the WCF library, all code is copied from a MSDN article (link in code).
  • Client, a Windows Forms application with a service reference to the WCF service. Calls the service method on button click.

For debugging run VS as Administrator, this is necessary for service to register the base url. As alternative the solution can be compiled and set as single-startup project for Client. Then you run the server console manually from Windows Explorer with admin rights (right-click .exe, run as Admin), then run/debug just client. This is also useful if you want to change base url and need to update the service reference in Client project.

Special considerations:
  • service method returns a Stream for image bytes rather than Image, because an Image object is not suitable for WCF message transmission.
  • the BasicHttpBinding in client app.config is modified for larger message size, because images takes more space than default message size.
 

Attachments

  • WCF-test.zip
    49.6 KB · Views: 47
Hi John so I decided that WCF may be better it works great when both are on the localhost however I want to run the server from the server and the clients from various lan IP address's So I changed the server Line to http://192.168.254.1:8080/hello
the console starts ok. But cant seem to figure out how to get the client to connect. The ultimate goal here is to have each client get a screen update from the server every second. Its looks as if I need to change the endpoint configuration according to the error message. I figured out that the endpoint was in the app.config file I pointed it to <endpoint address="http://192.168.254.1:8080/hello" binding="basicHttpBinding" but when I try to run more than one instance it cant because file is in use. Any thoughts on this?
Thanks Dwain
 
Last edited:
You can re-configure the client server reference within VS when you have server up, or you can manually change "client > binding" in clients app.config, this can also be done with the clients .config file manually after compile/deploy.
 
Sorry having a senior moment lol. I was trying to run the same app twice of course the file was in use. The end result was editing the app config file as stated above.
 
Back
Top