Reputation: 1
I'm hosting a HTTP WCFService in a Windows Service, in local network it works perfectly, but if the client is in another network and try to connect with de public IP doesn't work.
Config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config
file must be added to the host's
app.config file. System.Configuration does not support config files for
libraries. -->
<system.serviceModel>
<services>
<service name="WCFService.ServiceBehavior">
<endpoint address="" binding="wsHttpBinding"
contract="WCFService.ServiceContract">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:80/WCFService/service/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Upvotes: 0
Views: 775
Reputation: 11
The service metadata publishes http://localhost:80/WCFService/service/ to the client. This URL is not accessible from outside the local host.
In order to access the service from another network using a public IP the service metadata should publish http://PUBLIC_IP_ADDRESS/WCFService/service/ to the client. This can be done dynamically depending on the URL used by the client. Just add useRequestHeadersForMetadataAddress to service behaviors.
<behaviors>
<serviceBehaviors>
<behavior name="...">
...
<useRequestHeadersForMetadataAddress />
</behavior>
</serviceBehaviors>
</behaviors>
See Auto-resolving a hostname in WCF Metadata Publishing.
Upvotes: 1
Reputation: 2205
I suspect that when you give a config like this:
<add baseAddress="http://localhost:80/WCFService/service/" />
It would be listening in the loopback address due to the usage of locahost. Change this to the actual public IP address (i.e., not 127.0.0.1) or Server name and check again.
Upvotes: 0