2010-01-25 48 views
1

我在開發機器上構建了一個WCF Web服務。我構建了這個服務,創建了一個測試客戶端,測試了一切,並且它工作正常我開始對這個WCF的東西感覺很不錯。然後我大膽地將它移到我的生產服務器上。操作方法:將WCF服務從本地主機移動到生產服務器

現在,生產服務器位於WinHost.com上。我有我的測試域www.MyDomain.com,創建了一個應用程序文件夾/ websvc,並將該Web服務文件複製到其中。服務地址是http://www.MyDomain.com/websvc/eval.svc

現在我已經轉移到生產服務器,我無法使用Web服務。我得到這個錯誤 - 「這個集合已經包含一個地址與方案http。」我搜索瞭解決方案的信息,嘗試了一些,但這隻會導致其他錯誤。所以我重置了一切,我重新開始。

根據上面的服務地址,我的web.config應該是什麼樣子?具體來說,我的終端應該如何查看它?

這是我現在有...

<configuration> 
    <system.serviceModel> 
    <services> 
     <service name="EvalServiceLibrary.EvalService"> 
     <endpoint address="http://www.MyDomain.com:80/websvc/mex" 
      binding="mexHttpBinding" contract="IMetadataExchange" /> 
     <endpoint address="http://www.MyDomain.com:80/websvc/basic" 
      binding="basicHttpBinding" contract="EvalServiceLibrary.IEvalService" /> 
     </service> 
    </services> 

    <behaviors> 
     <serviceBehaviors> 
     <behavior name="ServiceBehavior"> 
      <!-- 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

這是您嘗試從應用程序使用服務時獲得的消息嗎?啓用'includeExceptionDetailInFaults',然後在瀏覽器中導航到服務*的位置。*它顯示了什麼?順便提一下,您在問題中列出的地址與Web.config文件中的端點地址不匹配。 – Jay 2010-01-25 02:11:20

+0

您能指出端點地址的區別嗎?我沒有看到它。當我嘗試訪問http://www.MyDomain.com:80/websvc/eval.svc/basic – DenaliHardtail 2010-01-25 02:28:20

+0

時,錯誤消息在我的瀏覽器中消失了。描述中的地址是「websvc/eval.svc」,而在它被稱爲'basic'。 – Jay 2010-01-25 06:28:47

回答

1

如上所述,Web服務現在可以在第三方服務上運行和託管。正在使用的web.config在下面。

獲得的經驗:編寫WCF Web服務的代碼並不困難,但配置端點可能會有點麻煩。

<?xml version="1.0"?> 
<!-- 
    Note: As an alternative to hand editing this file you can use the 
    web admin tool to configure settings for your application. Use 
    the Website->Asp.Net Configuration option in Visual Studio. 
    A full list of settings and comments can be found in 
    machine.config.comments usually located in 
    \Windows\Microsoft.Net\Framework\v2.x\Config 
--> 
<configuration> 

    <system.serviceModel> 

    <serviceHostingEnvironment aspNetCompatibilityEnabled="false"> 
     <!-- modified section here--> 
     <baseAddressPrefixFilters> 
     <add prefix="http://www.MyDomain.com:80/websvc/eval.svc"/> 
     </baseAddressPrefixFilters> 
    </serviceHostingEnvironment> 

    <services> 
     <service behaviorConfiguration="ServiceBehavior" name="EvalServiceLibrary.EvalService"> 
     <endpoint address="" binding="basicHttpBinding" contract="EvalServiceLibrary.IEvalService" /> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     </service> 
    </services> 

    <behaviors> 
     <serviceBehaviors> 
     <behavior name="ServiceBehavior"> 
      <!-- 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

它只是意味着當你在託管IIS服務沒有必要指定的基址。它已經由IIS虛擬目錄定義。僅僅用這個替換您的塊:

<services> 
    <service name="EvalServiceLibrary.EvalService"> 
    <endpoint address="mex" 
     binding="mexHttpBinding" contract="IMetadataExchange" /> 
    <endpoint address="basic" 
     binding="basicHttpBinding" contract="EvalServiceLibrary.IEvalService" /> 
    </service> 
</services> 
1

每次我碰到的這個時候,那是因爲IIS配置爲通過名稱的多個虛擬主機(在宿主方案中一個常見的配置)。 Here是解決這個問題的好方法,這對我來說一直有效 - 請注意,您需要明確且準確地定義您的端點地址,包括正確的主機名(它看起來像是或多或少)。

我已經提出連接錯誤周圍,它應該是更好的4.0,但我還沒有嘗試過呢。