簡體   English   中英

錯誤:無法從 http://localhost 獲取元數據:如果這是 Windows (R) Communication Foundation 服務

[英]Error: Cannot obtain Metadata from http://localhost: If this is a Windows (R) Communication Foundation service

我剛剛創建了第一個 SVC Rest 服務,並在 web.config 中進行了可能的更改,但在編譯期間,出現錯誤:添加服務失敗。 服務元數據可能無法訪問。 確保您的服務正在運行並公開元數據。

這是我的服務界面

[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "/GetPolicyDetailsByMoblieNumberJson", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
GetPolicyDetailsByMoblieNumberJson GetPolicyDetailsByMoblieNumberJson(string mobileNumber);

這是SVC

public GetPolicyDetailsByMoblieNumberJson GetPolicyDetailsByMoblieNumberJson(string mobileNumber)
{
// Some Method
}

在 Web 配置文件中,我進行了以下更改

在下面 -

<system.serviceModel>
    <behaviors>
   <endpointBehaviors>
        <behavior name="web">
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehaviour">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>       
 </behaviors>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" />
 <client>
 </client>
 <services>
      <service behaviorConfiguration="ServiceBehaviour" name="XRM.Automation.WebService.JsonService">
        <endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" contract="XRM.Automation.WebService.IJsonService" />
      </service>
</services>

解決了

<service behaviorConfiguration="ServiceBehaviour" name="XRM.Automation.WebService.JsonService">
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:50975/JsonService.svc" />
      </baseAddresses>
    </host>
    <endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" contract="XRM.Automation.WebService.IJsonService" />
</service>

暫無
暫無

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

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