2014-02-11 38 views
0

我試圖創建一個基本的WCF應用程序,但是當我運行它,我得到一個錯誤:WCF錯誤「具有零的應用程序(非基礎設施)端點」

這是服務:

namespace WcfTranslationLibrary 
{ 
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together. 
    [ServiceContract] 
    public interface ITranslationService 
    { 
     [OperationContract] 
     string Translate(string value); 

     // TODO: Add your service operations here 
    } 
} 

這是我的課:

namespace WcfTranslationLibrary 
{ 
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together. 
    public class PigLatinTranslator : ITranslationService 
    { 
     public string Translate(string value) 
     { 
      return string.Format("You entered: {0}", value); 
     } 
    } 
} 

這是我App.config文件:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 

    <appSettings> 
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /> 
    </appSettings> 
    <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> 
    <services> 
     <service name="WcfTranslationLibrary.PigLatinTranslator"> 
     <endpoint address="" binding="basicHttpBinding" contract="WcfTranslationLibrary.ITranslationService"> 
      <identity> 
      <dns value="localhost" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost:8733/Design_Time_Addresses/WcfTranslationLibrary/PigLatinTranslator/" /> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <!-- To avoid disclosing metadata information, 
      set the values below to false before deployment --> 
      <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/> 
      <!-- To receive exception details in faults for debugging purposes, 
      set the value below to true. Set to false before deployment 
      to avoid disclosing exception information --> 
      <serviceDebug includeExceptionDetailInFaults="False" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 

</configuration> 

,這是控制檯應用程序,我使用:

namespace ServiceHostConsoleApp 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      ServiceHost myHost = new ServiceHost(typeof(PigLatinTranslator)); 
      myHost.Open(); 
      Console.WriteLine("Translator running..."); 
      Console.ReadLine(); 
      myHost.Close(); 

     } 
    } 
} 

任何想法?

回答

0
static void Main(string[] args) 
     { 
      Uri baseAddress = new Uri("http://localhost:8080/hello"); <--url 

      // Create the ServiceHost. 
      using (ServiceHost host = new ServiceHost(typeof(HelloWorldService), baseAddress)) <-- url 
      { 
       // Enable metadata publishing. 
       ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); <-- metadata 
       smb.HttpGetEnabled = true; 
       smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15; 
       host.Description.Behaviors.Add(smb); 

       // Open the ServiceHost to start listening for messages. Since 
       // no endpoints are explicitly configured, the runtime will create 
       // one endpoint per base address for each service contract implemented 
       // by the service. 
       host.Open(); 

       Console.WriteLine("The service is ready at {0}", baseAddress); 
       Console.WriteLine("Press <Enter> to stop the service."); 
       Console.ReadLine(); 

       // Close the ServiceHost. 
       host.Close(); 
      } 
     } 
    } 

我想你錯過了一些設置,至少網址,看看到樣品通過msdn

提供
相關問題