Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Sorry, I totally forgot the example (:-$).</p> <p>Here is my code for the server:<br> <code>ISpotifyServer.cs</code></p> <pre><code>[ServiceContract(CallbackContract = typeof(ISpotifyCallback))] public interface ISpotifyService { [OperationContract(IsOneWay = true)] void Login(string username, string password); } </code></pre> <p><code>ISpotifyCallback.cs</code></p> <pre><code>[ServiceContract] public interface ISpotifyCallback { [OperationContract(IsOneWay = true)] void OnLoginComplete(); [OperationContract(IsOneWay = true)] void OnLoginError(); } </code></pre> <p><code>Program.cs</code></p> <pre><code>class Program { static void Main(string[] args) { using (ServiceHost host = new ServiceHost(typeof(SpotifyService))) { host.Open(); Console.WriteLine("Service running."); Console.WriteLine("Endpoints:"); foreach (ServiceEndpoint se in host.Description.Endpoints) Console.WriteLine(se.Address.ToString()); Console.ReadLine(); host.Close(); } } } </code></pre> <p><code>AppData.xml</code></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;configuration&gt; &lt;system.serviceModel&gt; &lt;behaviors&gt; &lt;serviceBehaviors&gt; &lt;behavior name="MetadataEnabledBehavior"&gt; &lt;serviceMetadata /&gt; &lt;serviceDebug includeExceptionDetailInFaults="True"/&gt; &lt;/behavior&gt; &lt;/serviceBehaviors&gt; &lt;/behaviors&gt; &lt;services&gt; &lt;service behaviorConfiguration="MetadataEnabledBehavior" name="SpotiServer.SpotifyService"&gt; &lt;host&gt; &lt;baseAddresses&gt; &lt;add baseAddress="net.tcp://localhost:9821" /&gt; &lt;/baseAddresses&gt; &lt;/host&gt; &lt;clear /&gt; &lt;endpoint address="spotiserver" binding="netTcpBinding" name="TcpEndpoint" contract="SpotiServer.ISpotifyService" listenUriMode="Explicit"&gt; &lt;identity&gt; &lt;dns value="localhost"/&gt; &lt;certificateReference storeName="My" storeLocation="LocalMachine" x509FindType="FindBySubjectDistinguishedName" /&gt; &lt;/identity&gt; &lt;/endpoint&gt; &lt;endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" /&gt; &lt;/service&gt; &lt;/services&gt; &lt;/system.serviceModel&gt; &lt;/configuration&gt; </code></pre> <p>And for the client:<br> <code>Program.cs</code></p> <pre><code>class Program { static void Main(string[] args) { InstanceContext context = new InstanceContext(new CallbackHandler()); String username; String password; Console.Write("Username: "); username = Console.ReadLine(); Console.WriteLine("Password: "); password = ReadPassword(); SpotiService.SpotifyServiceClient client = new SpotiService.SpotifyServiceClient(context); client.Login(username, password); Console.ReadLine(); } private static string ReadPassword() { Stack&lt;string&gt; passbits = new Stack&lt;string&gt;(); //keep reading for (ConsoleKeyInfo cki = Console.ReadKey(true); cki.Key != ConsoleKey.Enter; cki = Console.ReadKey(true)) { if (cki.Key == ConsoleKey.Backspace) { //rollback the cursor and write a space so it looks backspaced to the user Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop); Console.Write(" "); Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop); passbits.Pop(); } else { Console.Write("*"); passbits.Push(cki.KeyChar.ToString()); } } string[] pass = passbits.ToArray(); Array.Reverse(pass); return string.Join(string.Empty, pass); } } </code></pre> <p>I think that's about all. I of cause also have an implementation of the interfaces, that (on the client-side) prints the result to the console, and on the serverside runs "OnLoginComplete" if user-name and password is correct, otherwise runs "OnLoginError". Let me know if it doesn't work or if you need help setting it all up.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload