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

1.6k views Asked by At

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

There are 1 answers

1
Consultant AnuragDubey On

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>