Ошибка удалённого доступа к WSF-службе
От: VMak  
Дата: 03.05.13 14:31
Оценка:
Добрый день всем!

В VS2010 на .NET4 написал тривиальную WCF-службу.
Сделал хост (self-hosting) в виде консольного App.
После запуска хоста запускаю WcfTestClient.exe
и ввожу следующую строку в команде Add Service.
1). При отключённом интернете:
http://localhost:80/MyWcfService — всё OK ("Service added successfully").
2). На той же машине при включённом интернете и отключенном файрволе:
http:// xx.xx.xxx.xxx:80/MyWcfService — выдаёт HTTP GET Error (404).

При этом xx.xx.xxx.xxx — внешний IP с доступом по всем портам
(пингуется с удалённой машины нормально).
Как наладить доступ к службе с удалённой машины ?
Спасибо.

WCF-служба:
namespace MyWcfServiceNamespace
{
    [ServiceContract]    
    public interface IMyWcfService
    {
        [OperationContract]
        String MyWcfOperation( String inputString);
    }
}

namespace MyWcfServiceNamespace
{
    public class MyWcfService : IMyWcfService
    {
        public String MyWcfOperation( String inputString)
        {
            return "From_MyWcfOperation_" + inputString;
        }
    }
}


Хост службы:
   class Program
    {
        static void Main(string[] args)
        {
            ServiceHost host = new ServiceHost( typeof( MyWcfService));
            host.Open();
            Console.WriteLine("Хост открыт. \nНажмите любую клавишу для выхода");
            Console.ReadKey(true);
            host.Close();
        }
    }


app.config хоста:


<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="MyWcfServiceNamespace.MyWcfService" behaviorConfiguration="MEXGET">
        <host>
          <baseAddresses>
            <add baseAddress="http://xx.xx.xxx.xxx:80/MyWcfService/"/>
          </baseAddresses>
        </host>
        <endpoint address=""
                  binding="basicHttpBinding"
                  contract="MyWcfServiceNamespace.IMyWcfService">
        </endpoint>
        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange">
        </endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MEXGET">
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>


Сообщение об ошибке:
----------------------
Error: Cannot obtain Metadata from http://xx.xx.xxx.xxx/MyWcfService
If this is a Windows (R) Communication Foundation service to which you have access,
please check that you have enabled metadata publishing at the specified address.
For help enabling metadata publishing, please refer to the MSDN documentation at
http://go.microsoft.com/fwlink/?LinkId=65455.

WS-Metadata Exchange Error URI: http://xx.xx.xxx.xxx/MyWcfService
Metadata contains a reference that cannot be resolved: 'http://xx.xx.xxx.xxx/MyWcfService'.

There was no endpoint listening at http://xx.xx.xxx.xxx/MyWcfService that could
accept the message. This is often caused by an incorrect address or SOAP action.
See InnerException, if present, for more details.

The remote server returned an error: (404) Not Found.HTTP GET Error
URI: http://xx.xx.xxx.xxx/MyWcfService

There was an error downloading 'http://xx.xx.xxx.xxx/MyWcfService'.
The request failed with HTTP status 404: Not Found.
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.