简体   繁体   中英

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

I just created first SVC Rest Service, and make the possible changes in web.config, but during complile time, it got error: Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.

This is my Service Interface

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

This is SVC

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

In Web Config File i make below changes

Under -

<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>

Solved

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM