2010-09-17 68 views
1

我有一個名爲「GetNameService」的wcf可發現服務,它位於PC @ 10.0.0.5:8732上。它使用wsHttpBinding進行託管,並可通過'UdpEndpoint發現。我也有一個client @ 10.0.0.9,它在同一個網絡中發現了這樣的服務。當我運行客戶端時,我能夠發現服務,但發現的服務的終點是有本地主機。這怎麼可能發生,請幫我解決這個問題。WCF發現找到端點,但地址是本地主機

一些詳細信息,

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> 
    <services> 
    <service name="NameService.GetNameService"> 
    <host> 
    <baseAddresses> 
     <add baseAddress = "http://10.0.0.5:8732/Design_Time_Addresses/NameService/GetNameService/" /> 
    </baseAddresses> 
    </host> 
    <!-- Service Endpoints --> 
    <!-- Unless fully qualified, address is relative to base address supplied above --> 
    <endpoint address ="" binding="wsHttpBinding" contract="NameService.IGetNameService"> 
    <!-- 
     Upon deployment, the following identity element should be removed or replaced to reflect the 
     identity under which the deployed service runs. If removed, WCF will infer an appropriate identity 
     automatically. 
    --> 
    <identity> 
     <dns value="localhost"/> 
    </identity> 
    </endpoint> 
    <!-- Metadata Endpoints --> 
    <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. --> 
    <!-- This endpoint does not use a secure binding and should be secured or removed before deployment --> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
    </service> 
    </services> 
    <behaviors> 
    <serviceBehaviors> 
    <behavior> 
    <!-- To avoid disclosing metadata information, 
    set the value below to false and remove the metadata endpoint above before deployment --> 
    <serviceMetadata httpGetEnabled="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> 

我打開了在客戶機瀏覽器和輸入的服務地址,我能看到服務的詳細信息頁面,但仍然是WSDL鏈接指向本地主機(如下所示)

svcutil.exe的http://localhost:8732/Design_Time_Addresses/NameService/GetNameService/?wsdl

代替

svcutil.exe的http://10.0.0.5:8732/Design_Time_Addresses/NameService/GetNameService/?wsdl

此外,相同的應用程序似乎是在我工作的地方工作,那裏是一個DNS可與系統相連通」的開關,在那裏,因爲它沒有在我的工作通過路由器連接PC的家。這會影響一些東西嗎?!?

更新 這不是在IIS中運行,它託管直通」一個正常的控制檯應用程序

回答

1

如果你正在運行在IIS上,你必須有你的網站默認的主機名的規則:

  1. 打開IIS
  2. 鼠標右鍵點擊你的網站,然後單擊「屬性」
  3. 單擊「網站」選項卡,第單擊「網站標識」標題下的「高級」按鈕
  4. 您應具有網站的默認標識(TCP端口8732)。編輯並確保主機標頭值是您的網站的域名(所以它應該說www.yourdomain.com)

請參閱http://forums.asp.net/p/1096811/1659596.aspx從更多的細節。

+0

它不是託管在IIS,託管直通」一個控制檯應用程序 – sudarsanyes 2010-09-17 10:46:23

0

通過使用代碼(用於tcp.net連接)解決它。

// Add discovery feature. 
m_Host.AddServiceEndpoint(new Discovery.UdpDiscoveryEndpoint()); 
m_Host.Description.Behaviors.Add(new Discovery.ServiceDiscoveryBehavior()); 
// Add ordinary service feature 
var binding = new NetTcpBinding(); 
binding.Security.Message.ClientCredentialType = MessageCredentialType.None; 
binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None; 
m_Host.AddServiceEndpoint(
     typeof(IMyServiceContract), 
     new NetTcpBinding(SecurityMode.None), 
     new UriBuilder { Scheme = Uri.UriSchemeNetTcp, Port = 8732, Host = "10.0.0.5" , Path = "MyServiceContractPath" }.Uri 
     ); 

唯一的(也許是更小的)的問題,仍然是電腦IP設置爲主機...的URI輸入是在DiscoveryClient.Find(...)響應中返回的一個。

0

在你仍然需要這種情況下,事實證明,你可以使用baseAddress通配符:

<add baseAddress = "http://*:8732/Design_Time_Addresses/NameService/GetNameService/" /> 
+0

我不能在代碼中使用此當做'新的ServiceHost(typeof(MyService),新的Uri('http:// *:8080/MyService'));'。它說主機名不能被解析。有什麼建議麼? – 2016-08-24 20:54:36

相關問題