簡體   English   中英

Unity WCF服務托管

[英]Unity WCF Service Hosting

我試圖在Unity測試應用中自托管WCF服務。

打開服務時未報告任何錯誤,但我無法訪問它或其元數據(使用VS 2013附帶的WcfTestClient進行了測試)。

這是我用來創建服務的代碼:

_host = new ServiceHost(typeof(HomeAutomationService), new Uri("http://0.0.0.0:38001/"));
ServiceMetadataBehavior smb = _host.Description.Behaviors.Find<ServiceMetadataBehavior>() ??
                                new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
_host.Description.Behaviors.Add(smb);


_host.AddServiceEndpoint(typeof(IHomeAutomationService), new BasicHttpBinding(), "");
_host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
    MetadataExchangeBindings.CreateMexHttpBinding(), "mex");

_host.Faulted += HostOnFaulted;

_host.Open();

我正在嘗試使用以下Uri訪問本地計算機上的元數據: http:// localhost:38001 / mex ,但這僅返回HTTP400錯誤

您需要向服務添加元數據交換(mex)端點:

<services>
   <service name="MyService.MyService" behaviorConfiguration="metadataBehavior">
      <endpoint 
          address="http://localhost/MyService.svc" 
          binding="customBinding" bindingConfiguration="jsonpBinding" 
          behaviorConfiguration="MyService.MyService"
          contract="MyService.IMyService"/>
      <endpoint 
          address="mex" 
          binding="mexHttpBinding" 
          contract="IMetadataExchange"/>
   </service>
</services>

暫無
暫無

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

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