I am hosting a WCF Service as a Windows Service.
A snapshot below.
myHost = new ServiceHost(typeof(AnalyticsService));
Uri address = new Uri("http://localhost:8080/MathServiceLibrary");
WSHttpBinding binding = new WSHttpBinding();
binding.MaxReceivedMessageSize = 2147483647;
binding.MaxBufferPoolSize = 2147483647;
//binding.Security.Mode = SecurityMode.None;
Type contract = typeof(IAnalyticsService);
myHost.AddServiceEndpoint(contract,binding,address);
As you can see I have previously been only exposing the Service locally. I would like add another ServiceEndpoint so that other machines on my network can also call the service.
I assume I would need to add something like this to the above code:
myHost = new ServiceHost(typeof(AnalyticsService));
Uri address = new Uri("http://localhost:8080/MathServiceLibrary");
Uri new address = new Uri("http://xxx.xxx.xxx:8080/MathServiceLibrary");
WSHttpBinding binding = new WSHttpBinding();
binding.MaxReceivedMessageSize = 2147483647;
binding.MaxBufferPoolSize = 2147483647;
Type contract = typeof(IAnalyticsService);
myHost.AddServiceEndpoint(contract, binding, address);
myHost.AddServiceEndpoint(contract, binding, newaddress);
Now my current service library APP config looks like:
<system.serviceModel>
<services>
<service behaviorConfiguration="ServiceLibrary.Service1Behavior"
name="ServiceLibrary.AnalyticsService">
<endpoint address="" binding="wsHttpBinding" contract="ServiceLibrary.IAnalyticsService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8731/Design_Time_Addresses/ServiceLibrary/Service1/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceLibrary.Service1Behavior">
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
While my app.config
in the Service Library host is
<system.serviceModel>
<services>
<service name="ServiceLibrary.AnalyticsService"
behaviorConfiguration ="MathServiceMEXBehavior">
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/MathService"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MathServiceMEXBehavior">
<serviceMetadata httpGetEnabled="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
I assume I need to add another base address to the service library file with the external (non-local-host) address. I am confused about what to alter in the Service Library File.