Skip to content

Instantly share code, notes, and snippets.

@teyc
Last active August 29, 2015 14:20
Show Gist options
  • Save teyc/554aa42d28f78d0f2881 to your computer and use it in GitHub Desktop.
Save teyc/554aa42d28f78d0f2881 to your computer and use it in GitHub Desktop.
WCF
<!-- configuration using XML -->
<system.serviceModel>
<services>
<service name="Sample.MyService">
<endpoint address="net.tcp://localhost:8009/myservice"
binding="netTcpBinding"
contract="Sample.IMyService" />
</service>
</services>
</system.serviceModel>
<!-- configuration with Custom Host Factory -->
<system.serviceModel>
<services>
<service name="Sample.MyService">
<endpoint address=""
binding="wsHttpBinding"
contract="Sample.IMyService"
factory="Sample.CustomHostFactory" />
</service>
</services>
<serviceHostingEnvironment>
<serviceActivations>
<add service="Sample.MyService"
relativeAddress="MyService.svc" />
</serviceActivations>
</serviceHostingEnvironment>
</system.serviceModel>
public class CustomHostFactory : ServiceHostFactory
{
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
ServiceHost host = new ServiceHost(serviceType, baseAddresses);
// ... now can configure endpoints programmatically if required
return host;
}
}
static void Main()
{
ServiceHost host = new ServiceHost(typeof(MyService));
string address = "net.tcp://localhost:8009/myservice";
Binding binding = new NetTcpBinding();
Type contract = typeof(IMyService);
host.AddServiceEndPoint(contract, binding, address);
host.Open();
Console.ReadLine();
host.Close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment