簡體   English   中英

部署WCF服務,C#,WCF,VS2008

[英]Deploy WCF service, C#, WCF, VS2008

我有一個測試項目WCF服務庫,並且已發布該項目。 安裝所有正確安裝的2003服務器。 我瀏覽到我的應用程序,然后在單擊.svc時出現此錯誤。

找不到類型“ SearchService”(在ServiceHost指令中作為服務屬性值提供)。

這是我的web.config中的代碼片段

<endpoint address="" binding="wsHttpBinding" contract="TestService.ISearchService">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>

我的界面:

  [ServiceContract]
public interface ISearchService
{
    [OperationContract]
    string GetName();
}

我的實現:

   [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession)]
public class SearchService :ISearchService
{
    #region ISearchService Members

    public string GetName()
    {
      returnn "HAL-2001" 
    }

 }

好吧,wsHttpBinding要求您使用SOAP連接到服務-單獨的Web瀏覽器不會削減它,因此這就是為什么當您瀏覽到.svc文件時它不起作用的原因。 真的沒錯。

您需要創建一個真正的成熟的SOAP客戶端以連接到您的服務並對其進行測試。 或者,您也可以使用WcfTestClient.exe測試客戶端,該客戶端位於VS2008\\Common7\\IDE文件夾中。

不能,該錯誤表明主機在您的web.config中找不到服務實現“ SearchService”的定義。 在web.config中,您需要將<endpoint>標記包裝在<service>標記中。 <service>的name屬性應設置為SearchService類的全名(包括所有名稱空間)。 您還需要定義一個行為以使服務能夠在瀏覽器中顯示WSDL。 在將服務部署到服務器時,您可能還想刪除<dns value =“ localhost” />。

這是一個示例片段,請確保將SearchService的完整類名稱放入<service>標記中,並且還應確保完整的類名稱位於.svc文件中:

<system.serviceModel>
 <services>
  <service name="SearchService" behaviorConfiguration="ServiceBehavior">
    <endpoint address="" binding="wsHttpBinding" contract="TestService.ISearchService">
    </endpoint>
    <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>

不能,您應該切換到basicHttpBinding並進行測試以確保一切正常。 您正在使用WSHttpBinding,並且默認情況下它已啟用身份驗證。 您的客戶需要傳遞憑據才能真正獲得響應,這就是瀏覽器調用無法正常工作的原因。

您的客戶代碼調用什么? 為此,它應該像下面這樣調用代理類。

class SearchServiceProxy : ClientBase<ISearchService>, ISearchService
{
    public string GetName()
    {
        return Channel.GetName();
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM