2014-09-25 3 views
0

У меня есть основной проект библиотеки WCF, который я пытаюсь разместить в консольном приложении. Основной метод файла Program.cs приведен ниже:WCF service 404 Не найдено

static void Main(string[] args) 
    { 
     // Create a binding and set the security mode to Message. 
     BasicHttpBinding b = new BasicHttpBinding();//WSHttpBinding(SecurityMode.Message); 

     Type contractType = typeof(SecureWCFLib.IService1); 
     Type implementedContract = typeof(SecureWCFLib.Service1); 

     Uri baseAddress = new Uri("http://localhost:8733/Design_Time_Addresses/SecureWCFLib/Service1/"); 

     ServiceHost sh = new ServiceHost(implementedContract, baseAddress); 

     sh.AddServiceEndpoint(contractType, b, "Service1"); 

     ServiceMetadataBehavior sm = new ServiceMetadataBehavior(); 
     sm.HttpGetEnabled = true; 
     sh.Description.Behaviors.Add(sm); 

     sh.Open(); 
     Console.WriteLine("Listening"); 
     Console.ReadLine(); 
     sh.Close(); 


    } 

У меня есть другое консольное приложение, которое действует как клиент. Я пытаюсь потреблять услугу в Program.cs, как указано ниже:

static void Main(string[] args) 
     { 
      IService1 productChannel = null; 
      EndpointAddress productAddress = new EndpointAddress("http://localhost:8733/Design_Time_Addresses/SecureWCFLib/Service1/"); 
      productChannel = ChannelFactory<IService1>.CreateChannel(new BasicHttpBinding(), productAddress); 
      string result = productChannel.GetData(123); 
      Console.WriteLine(result); 
      Console.Read(); 
     } 

Но я получаю исключение, как

{"The remote server returned an error: (404) Not Found."}

Пожалуйста, дайте мне знать, что я делаю неправильно здесь.

+0

Пробовали ли вы доступ к вашему WCF URL в браузере? это открытие там? – SoftSan

+0

Да, он работает в браузере – 2014-09-25 06:05:31

ответ

0
EndpointAddress productAddress = new EndpointAddress("http://localhost:8733/Design_Time_Addresses/SecureWCFLib/Service1/Service1"); 

добавить обслуживания1 к концу параметра конструктора.

client endpointaddress = serviceshost_baseAddress + relative address. 

Ваш код Эквале конфигурации:

<service name="SecureWCFLib.Service1"> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost:8733/Design_Time_Addresses/SecureWCFLib/Service1/" /> 
      </baseAddresses> 
     </host> 
     <endpoint address="Service1" binding="basicHttpBinding" contract="SecureWCFLib.IService1"> 
     </endpoint> 
<behaviors> 
<!--......--> 
<behaviors> 
</service> 
0

Если у вас есть доступ к вашему веб-сервису на IIS, выражаемому другими клиентами, вы должны предоставить удаленный доступ к порту IIS express. См. Ниже ссылку.

http://johan.driessen.se/posts/Accessing-an-IIS-Express-site-from-a-remote-computer

http://www.iis.net/learn/extensions/using-iis-express/handling-url-binding-failures-in-iis-express

+0

Это не на IIS. Я использую сервер VS Development. – 2014-09-25 06:57:50

+0

Да, я знаю, но VS использует IIS EXPRESS. – aziz

Смежные вопросы