2014-03-29 173 views
0

我創建了WCF自託管服務,我託管它在C#控制檯應用程序中,它在那裏運行完美,但問題是,當我把本地URL在瀏覽器中,然後它不瀏覽+我不能添加它的參考Web表單客戶端應用程序,它會引發錯誤:無法添加WCF服務參考

There was an error downloading 'http://localhost:8084/_vti_bin/ListData.svc/$metadata'. 
Unable to connect to the remote server 
No connection could be made because the target machine actively refused it 127.0.0.1:8084 
Metadata contains a reference that cannot be resolved: 'http://localhost:8084/'. 
There was no endpoint listening at http://localhost:8084/ that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. 
Unable to connect to the remote server 
No connection could be made because the target machine actively refused it 127.0.0.1:8084 
If the service is defined in the current solution, try building the solution and adding the service reference again. 

我運行託管在VS 2013的獨立實例和客戶端在另一個作爲管理員,但它不能正常工作,爲什麼?

CODE:

託管應用:

namespace HellloServiceHost 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      using(ServiceHost sh = new ServiceHost(typeof(HellloService.HelloService))) 
      { 
       sh.Open(); 
       Console.WriteLine("Host Started @"+ System.DateTime.Now.ToShortDateString()); 
       Console.ReadLine(); 
      } 
     } 
    } 
} 

的app.config:

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

    <services> 
     <service name="HellloService.HelloService" behaviorConfiguration="MexBehaviour" > 
     <endpoint address="HelloService" binding="basicHttpBinding" contract="HellloService.IHelloService"></endpoint> 
     <endpoint address="HelloService" binding="netTcpBinding" contract="HellloService.IHelloService"></endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost:8084/"/> 
      <add baseAddress="net.tcp://localhost:8085/"/> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors > 
     <behavior name="MexBehaviour"> 
      <serviceMetadata httpGetEnabled="true"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 
</configuration> 
+0

有沒有任何答案可以幫助你。 – flayn

回答

0

您的配置文件中表明的服務地址是:

http://localhost:8084/HelloService 

嘗試要獲取的網址服務參考。如果仍然不起作用,請在服務啓動時嘗試打印端點地址。

0

每當我在控制檯託管服務,我轉儲的ServiceHost到控制檯的所有端點地址sh.Open()方法後:

foreach (var endpoint in sh.Description.Endpoints) 
{ 
    Console.WriteLine(endpoint.Address.Uri); 
} 

這適用於通過config文件配置端點或者如果你在代碼中創建它們。