Konfigurationsvereinfachungen bei WCF 4.0

  

» Von , 07.12.2009 18:34.

Listing 3: Ein Host-Beispiel bei WCF 4.0

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.ServiceModel;
using SimpleConfigSample;

namespace SampleService
{
class Program
{
// Host the service within this EXE console application.
public static void Main()
{
// Create a ServiceHost for the CalculatorService type.
using (ServiceHost serviceHost = new ServiceHost(typeof(Service1),
new Uri("http://localhost:8080/Http/Service.svc"),
new Uri("net.tcp://localhost/Tcp/Service.svc")))
{
// Open the ServiceHost to create listeners and start listening for messages.
serviceHost.Open();

// The service can now be accessed.
Console.WriteLine("The service is ready.");
Console.WriteLine("Press <ENTER> to terminate service.");
Console.WriteLine();
Console.ReadLine();
}
}
}
}

Listing 4: WCF 4.0-Konfiguration



<?xml version="1.0" encoding="utf-8" ?>
<configuration>
</configuration>



Listing 5: WCF 4.0-Konfiguration mit verändertem BasicHttpBinding



<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>

<bindings>

<basicHttpBinding>
<binding name="standardHttpBinding" >
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows"></transport>
</security>
<readerQuotas/>
</binding>
</basicHttpBinding>

</bindings>
</system.serviceModel>
</configuration>



Listing 6: WCF 4.0-Konfiguration mit Custom Protocol Mapping und CustomBinding



<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>

<bindings>

<protocolMapping>
<add scheme="http" binding="customBinding" />
</protocolMapping>
<basicHttpBinding>
<binding name="standardHttpBinding" >
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows"></transport>
</security>
<readerQuotas/>
</binding>
</basicHttpBinding>

</bindings>
</system.serviceModel>
</configuration>

Listing 7: Konfiguration mit ServiceBehavior-Section

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>

Listing 8: Konfiguration mit Activation-Elemente

<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<serviceHostingEnvironment>
<serviceActivations>
<add relativeAddress="~/MyService.svc" service="MySrviceClass"/>
</serviceActivations>
</serviceHostingEnvironment>
</system.serviceModel>
<system.web>
<compilation targetFramework="4.0" debug="true"/>
</system.web>
</Configuration>

Listing 9: WCF-Konfiguration mit udpDiscoverEndpoint

<configuration>
<system.serviceModel>
<services>
<service name="MyService">
<endpoint binding="basicHttpBinding" contract="IMyService"/>
<endpoint kind="udpDiscoveryEndpoint" <br> endpointConfiguration="MyUdpDisc"/>
</service>
</services>
<standardEndpoints>
<udpDiscoveryEndpoint>
<standardEndpoint name="MyUdpDisc" discoveryVersion="WSDiscovery11"/>
</udpDiscoveryEndpoint>
</standardEndpoints>
</system.serviceModel>
</configuration>

Werbung

KOMMENTARE

Keine Kommentare

KOMMENTAR SCHREIBEN

*
*
*
*

Alles Pflichfelder, E-Mail-Adresse wird nicht angezeigt.

Die Redaktion hält sich vor, unangebrachte, rassistische oder ehrverletzende Kommentare zu löschen.
Die Verfasser von Leserkommentaren gewähren der IDG Communications AG das unentgeltliche, zeitlich und räumlich unbegrenzte Recht, ihre Leserkommentare ganz oder teilweise auf dem Portal zu verwenden. Eingeschlossen ist zusätzlich das Recht, die Texte in andere Publikationsorgane, Medien oder Bücher zu übernehmen und zur Archivierung abzuspeichern.