WCF – Configure the entire self host service via the app.config only
App.config:
- The metadata can be access via the http://localhost:8080/DataAccessService/Mex.
- The service can be access via the net.tcp://localhost:8081/DataAccessService
<system.serviceModel> <behaviors> <serviceBehaviors> <behavior> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true" /> <dataContractSerializer maxItemsInObjectGraph="2147483647" /> </behavior> </serviceBehaviors> </behaviors> <bindings> <netTcpBinding> <binding name="IosService_netTcpBinding" maxReceivedMessageSize="2147483647" receiveTimeout="23:10:00"> <readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" /> <security mode="None" /> </binding> </netTcpBinding> <wsHttpBinding> <binding name="IosService_wsHttpBinding" maxReceivedMessageSize="2147483647" receiveTimeout="23:10:00"> <readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" /> <security mode="None" /> </binding> </wsHttpBinding> </bindings> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> <services> <service name="com_cae.Miss.ProductAdapter.CdbAdapter.DataAccess.DataAccessService"> <endpoint address ="" binding="netTcpBinding" bindingConfiguration="IosService_netTcpBinding" name="Endpoint" listenUriMode="Explicit" contract="com_cae.Miss.ProductAdapter.CdbAdapter.ClientServer.IDataAccessService" /> <endpoint address="mex" binding="mexHttpBinding" name="MexEndpoint" contract="IMetadataExchange" /> <host> <baseAddresses> <!-- For the metadata --> <add baseAddress="http://localhost:8080/DataAccessService/" /> <!--- For service --> <add baseAddress="net.tcp://localhost:8081/DataAccessService/" /> </baseAddresses> </host> </service> </services> </system.serviceModel>
Main Code :
try
{
ServiceHost wIosServiceHost = wFactory.CreateServiceHostWithType(typeof(DataAccessService));
wIosServiceHost.Open();
Console.WriteLine("running on endpoints:");
foreach (var wServiceEndpoint in wIosServiceHost.Description.Endpoints)
{
Console.WriteLine(wServiceEndpoint.Address.ToString());
Console.WriteLine("running");
}
}
catch (Exception ex)
{
...
}
No comments:
Post a Comment