Добрый день всем!
В 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.
Запустите например resmon и посмотрите кто юзает 80 порт на нужном интерфейсе. Скорее всего именно байндинг порта отваливается. Можно попробывать открыть иной порт для сервиса
RSDN на Windows Phone 1.5.0.0 WinPhone71_Release_20130421.1
Здравствуйте, ZmeyNet, Вы писали:
ZN> Можно попробывать открыть иной порт для сервиса
Заменил порт 80 на 8001.
В сообщении об ошибке всё то же самое, только
вместо "(404) Not Found" появилась фраза:
Unable to connect to the remote server
No connection could be made because the
target machine actively refused it xx.xx.xxx.xxx:8001
HTTP GET Error URI:
http://xx.xx.xxx.xxx:8001/MyWcfService
Здравствуйте, 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/