2011-01-03 5 views
0

Я новый с WCF. Я создаю wcf для сценария на стороне сервера ... Я размещаю wcf dll в консольном приложении. Ниже мой код:WCF на Windows 7 почему не работает.?

class Program 
{ 
    static void Main(string[] args) 
    { 
     using (ServiceHost host = new ServiceHost(typeof(PrintBarcode))) 
     { 
      host.Open(); 
      Console.WriteLine("The service is ready..."); 
      Console.WriteLine("Press <Enter> to stop the service."); 
      Console.ReadLine(); 
      host.Close(); 
     } 

    } 
} 

И это моя app.config:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <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> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> 
    <services> 
     <service behaviorConfiguration="CTIHandHeld.WCF.PrintBarcodeWcfServiceLibrary.Service1Behavior" 
     name="CTIHandHeld.WCF.PrintBarcodeWcfServiceLibrary.PrintBarcode"> 
     <endpoint address="" binding="netTcpBinding" bindingConfiguration="TcpBindingConfiguration" 
      contract="CTIHandHeld.WCF.PrintBarcodeWcfServiceLibrary.IPrintBarcode" /> 
     <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" 
      contract="IMetadataExchange" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="net.tcp://localhost:3518/PrintBarcodeService" /> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    <bindings> 
     <netTcpBinding> 
     <binding name="TcpBindingConfiguration"> 
      <security mode="Transport"/> 
     </binding> 
     </netTcpBinding> 
    </bindings> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="CTIHandHeld.WCF.PrintBarcodeWcfServiceLibrary.Service1Behavior"> 
      <serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" /> 
      <serviceDebug includeExceptionDetailInFaults="false" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 
</configuration> 

Этот код работает в Windows XP .... Почему его не будет работать, если я запустить его на Windows 7? Я запускаю его как администратора и отключен брандмауэр.

Документ отображается только в очереди на печать и исчезает без предупреждения или ошибки ... Но печать на самом деле не происходит.

ответ

1

Этот код работает в Windows XP .... Почему его не работает, если я запускаю его на окнах 7?

Вам необходимо запустить (хостинг) приложение в качестве администратора. Открытие порта для прослушивания - это привилегированная операция.

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