0% found this document useful (0 votes)
37 views3 pages

SignalR - Briefly HowTo

This document configures WCF message logging to log entire messages and messages at the service and transport levels with a maximum of 50,000 messages logged and a maximum message size of 20,000 bytes. It also configures ASP.NET Web API to use JSON formatting and map API routes. Finally, it outlines how to create a basic SignalR server and client to establish a connection and call methods between them.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views3 pages

SignalR - Briefly HowTo

This document configures WCF message logging to log entire messages and messages at the service and transport levels with a maximum of 50,000 messages logged and a maximum message size of 20,000 bytes. It also configures ASP.NET Web API to use JSON formatting and map API routes. Finally, it outlines how to create a basic SignalR server and client to establish a connection and call methods between them.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

WCF

<system.diagnostics>
<trace autoflush="true" />

<sources>
<source name="System.ServiceModel.MessageLogging">
<listeners>
<add name="myListener"/>
</listeners>
</source>
</sources>

<sharedListeners>
<add name="myListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="ServiceModel.svclog" />
</sharedListeners>
</system.diagnostics>

<system.serviceModel>
<diagnostics>
<messageLogging logEntireMessage="true"
logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="true"
logMalformedMessages="true"
maxMessagesToLog="50000"
maxSizeOfMessageToLog="20000" >
</messageLogging>
</diagnostics>
</system.serviceModel>
WebAPI
- create Web Application
- add NuGet package for WebAPI
- add WebApiConfig class

public static class WebApiConfig


{
public static void Register(HttpConfiguration config)
{
// ERST SPÄTER EINFÜGEN => NACH FIDDLER!
config.Formatters.Clear();
config.Formatters.Add(new JsonMediaTypeFormatter());

config.Routes.MapHttpRoute(
name: "Api1",
routeTemplate: "api/DGBB/{controller}/{action}",
defaults: new { action = "Get" });
}
}

- add Global.asax

protected void Application_Start(object sender, EventArgs e)


{
GlobalConfiguration.Configure(WebApiConfig.Register);
}

- add EventsController class

public string[] Get()


{
return new[] { "WebApi & SignalR", "Cross Platform Development", "Event 3"
};

- call in Browser => XML


- call in Fiddler => JSON
o Warum ist das so?
- setze content-type in Fiddler-Request => JSON
- configure Formatters
- zeigen in Browser und Fiddler
SignalR
Server
- add SignalR NuGet package
- add OWIN self hosting package
- add Startup class & configure SignalR
- add hub class
- add host class & start WebApp

In main:
var url = "http://localhost:8082";

using (WebApp.Start(url))
{
Console.WriteLine("\n[{0}] SignalR server listening on {1}.", DateTime.Now.To
String("dd-mm-yyyy hh:MM:ss"), url);
Console.ReadKey();
}

Client
- add SignalR Client NuGet package
- create hub connection
- create hub proxy from connection
- start connection
- register events to listen for with Proxy.On
- call server methods with Proxy.Invoke

var connection = new HubConnection("http://localhost:8082/");


connection.TraceLevel = TraceLevels.All;
connection.TraceWriter = Console.Out;

var proxy = _connection.CreateHubProxy("PlanningGridHub");

await _connection.Start(); ODER: _connection.Start().Wait();

proxy.Invoke("WriteMessage", "Hello!");

_proxy.On<string, decimal[]>("AccountDataChanged", (accountId, values) =>


{
DoSomething();
});

You might also like