Last active
August 29, 2015 14:20
-
-
Save teyc/554aa42d28f78d0f2881 to your computer and use it in GitHub Desktop.
WCF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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