2011-11-08 32 views
1

我目前有一個wcf服務庫項目,其中包含我的服務合同&的實現。如果我要在同一個解決方案中訪問Web項目並添加服務引用並單擊發現按鈕,我可以看到列出的我的服務列爲http://..design_time_address/myserviceWCF design_time_address在visual studio 2010中不顯示

現在,如果我繼續前進,並將我的服務合同&實施類別到另一個項目&配置我的wcf庫項目指向這個新項目,我發現,當我去嘗試發現內的服務我的web應用程序,我沒有看到design_time_address了。這不是發現什麼..

下面是我對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="Test.Server.Wcf.Service1"> 
     <host> 
      <baseAddresses> 
      <add baseAddress = "http://localhost:8732/Design_Time_Addresses/Test.Server.Wcf/Service1/" /> 
      </baseAddresses> 
     </host> 
     <!-- Service Endpoints --> 
     <!-- Unless fully qualified, address is relative to base address supplied above --> 
     <endpoint address ="" binding="wsHttpBinding" contract="Test.Server.Wcf.IService1"> 
      <!-- 
       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> 

,這裏是什麼樣子的舉動後

<?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="Test.Server.Core.Service1"> 
     <host> 
      <baseAddresses> 
      <add baseAddress = "http://localhost:8732/Design_Time_Addresses/Test.Server.Wcf/Service1/" /> 
      </baseAddresses> 
     </host> 
     <!-- Service Endpoints --> 
     <!-- Unless fully qualified, address is relative to base address supplied above --> 
     <endpoint address ="" binding="wsHttpBinding" contract="Test.Server.Core.IService1"> 
      <!-- 
       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> 

我在做什麼不正確?任何幫助將不勝感激。我一直停留在這幾個小時了,我覺得我失去了我的腦海裏......

感謝

+0

當你說「移動」的文件是你所做的?你需要添加「添加現有的項目...」 –

+0

是的,這就是我的意思是配置。對不起,我應該更清楚地指出。 – zSynopsis

回答

1

您使用添加服務引用的發現選項是內部的Visual Studio功能。什麼是啓動並列出它實際上可以找到實現的WCF服務。出於某種原因,它希望通過配置文件在WCF項目類型(庫或應用程序)中找到服務接口的實現。所以如果你把你的實現移動到Core項目是一個普通的類庫而沒有app.config文件,它不會發現你的服務了。

您可以做的是手動啓動您的服務,並通過瀏覽器訪問URL以添加服務參考。這只是發現選項,不再適用。

+0

如何在Visual Studio中手動啓動我的服務?我試着將項目設置爲啓動項目,然後點擊啓動調試按鈕,但它給我提示「目標程序集不包含任何服務類型。您可能需要調整此程序集的代碼訪問安全策略,然後停止運行。謝謝你的幫助! – zSynopsis

+0

啊,那就是catch :-)我通常會啓動第二個Visual Studio來啓動服務的調試會話並使用原始實例來創建服務引用。如果你的WCF服務部署在IIS中(比如WCF應用程序),你可以發佈你的服務並引用那個URL(儘管需要改變設計時地址)。 – kroonwijk