Re: Ошибка удалённого доступа к WSF-службе
От: irrona  
Дата: 07.05.13 18:06
Оценка:
Здравствуйте, VMak, Вы писали:

VM>Добрый день всем!


VM>В VS2010 на .NET4 написал тривиальную WCF-службу.

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

VM>При этом xx.xx.xxx.xxx — внешний IP с доступом по всем портам

VM>(пингуется с удалённой машины нормально).
VM>Как наладить доступ к службе с удалённой машины ?
VM>Спасибо.

VM>WCF-служба:

VM>
VM>namespace MyWcfServiceNamespace
VM>{
VM>    [ServiceContract]    
VM>    public interface IMyWcfService
VM>    {
VM>        [OperationContract]
VM>        String MyWcfOperation( String inputString);
VM>    }
VM>}

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


VM>Хост службы:

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


VM>app.config хоста:


VM>

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


VM>Сообщение об ошибке:

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

VM>WS-Metadata Exchange Error URI: http://xx.xx.xxx.xxx/MyWcfService

VM>Metadata contains a reference that cannot be resolved: 'http://xx.xx.xxx.xxx/MyWcfService'.

VM>There was no endpoint listening at http://xx.xx.xxx.xxx/MyWcfService that could

VM>accept the message. This is often caused by an incorrect address or SOAP action.
VM>See InnerException, if present, for more details.

VM>The remote server returned an error: (404) Not Found.HTTP GET Error

VM>URI: http://xx.xx.xxx.xxx/MyWcfService

VM>There was an error downloading 'http://xx.xx.xxx.xxx/MyWcfService'.

VM>The request failed with HTTP status 404: Not Found.

service name=

Очень распространенной ошибкой является отсутствие в URL конечного слэша. попробуйте так http://xx.xx.xxx.xxx/MyWcfService/
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.