[web-services] Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.`

EDIT:

After I modified the web.config and I don't get error that's good.... then I add a new page (html) and write this small code to consume the service like this:

 $("#btn12").click(function (event) {
                $.getJSON('http://localhost:3576/MyService.svc/GetCurrentUser', {},
                function (data) {
                    alert(data);
                });
                //return false;
            });

I see the following error in my FireBug:

http://localhost:3576/MyService.svc/GetCurrentUser
400 Bad Request

Note: I have added html page on the same wcf project and running the project it self so I am assuming the service is also running ...

What might be wrong here?

END EDIT

I have just created a new wcf services and when I hit f5 from VS and I get this error in WCF Test Client window :

Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.

Error: Cannot obtain Metadata from http://localhost:3696/MobileService.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.

WS-Metadata Exchange Error
URI: http://localhost:3696/MyService.svc
Metadata contains a reference that cannot be resolved: 'http://localhost:3696/MyService.svc'.

There was no endpoint listening at http://localhost:3696/MyService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

Unable to connect to the remote server
No connection could be made because the target machine actively refused it 127.0.0.1:3696
HTTP GET Error
URI: http://localhost:3696/MyService.svc
There was an error downloading 'http://localhost:3696/MyService.svc'.
Unable to connect to the remote server
No connection could be made because the target machine actively refused it 127.0.0.1:3696

My config:

<behaviors>
    <endpointBehaviors>
        <behavior name="MyService.MyService">
            <webHttp/>
        </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
        <behavior name="metadataBehavior">
            <serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost:2812/MyService.svc" />
        </behavior>
    </serviceBehaviors>
</behaviors>
<services>
    <service name="MyService.MyService" 
             behaviorConfiguration="metadataBehavior">
        <endpoint 
            address="http://localhost/MyService.svc" 
            binding="customBinding"
            bindingConfiguration="jsonpBinding" 
            behaviorConfiguration="MyService.MyService"
            contract="MyService.IMyService"/>
    </service>
</services>
<bindings>
    <customBinding>
        <binding name="jsonpBinding">
            <jsonpMessageEncoding/>
            <httpTransport manualAddressing="true"/>
        </binding>
    </customBinding>
</bindings>
<extensions>
    <bindingElementExtensions>
        <add name="jsonpMessageEncoding" type="Microsoft.Ajax.Samples.JsonpBindingExtension, MyService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
    </bindingElementExtensions>
</extensions>

This question is related to web-services wcf

The answer is


You need to add a metadata exchange (mex) endpoint to your service:

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

Now, you should be able to get metadata for your service

Update: ok, so you're just launching this from Visual Studio - in that case, it will be hosted in Cassini, the built-in web server. That beast however only supports HTTP - you're not using that protocol in your binding...

Also, since you're hosting this in Cassini, the address of your service will be dictated by Cassini - you don't get to define anything.

So my suggestion would be:

  • try to use http binding (just now for testing)
  • get this to work
  • once you know it works, change it to your custom binding and host it in IIS

So I would change the config to:

<behaviors>
   <serviceBehaviors>
      <behavior name="metadataBehavior">
         <serviceMetadata httpGetEnabled="true" />
      </behavior>
   </serviceBehaviors>
</behaviors>
<services>
   <service name="MyService.MyService" behaviorConfiguration="metadataBehavior">
      <endpoint 
          address=""   <!-- don't put anything here - Cassini will determine address -->
          binding="basicHttpBinding" 
          contract="MyService.IMyService"/>
      <endpoint 
          address="mex" 
          binding="mexHttpBinding" 
          contract="IMetadataExchange"/>
   </service>
</services>

Once you have that, try to do a View in Browser on your SVC file in your Visual Studio solution - if that doesn't work, you still have a major problem of some sort.

If it works - now you can press F5 in VS and your service should come up, and using the WCF Test Client app, you should be able to get your service metadata from a) the address that Cassini started your service on, or b) the mex address (Cassini's address + /mex)


if working with .NET 4.0 WCF service - make sure Global.asax is not in the source directory. If it is , it is picked up at runtime and attempted to be compiled in...


The property IsOneWay=true may be true in the Operational contract of the interface. Remove that property to get rid of this error.


I have tried several solutions mentioned over web, unfortunately without any success. In my project, I have two interfaces(xml/json) for each service. Adding mex endpoints or binding configurations did not helped at all. But, I have noticed, I get this error only when running project with *.svc.cs or *.config file focused. When I run project with IService.cs file focused (where interfaces are defined), service is added without any errors. This is really strange and in my opinion conclusion is bug in Visual Studio 2013. I reproduced same behaviour on several machines(even on Windows Server machine). Hope this helps someone.


In case you rename the svc file make sure that your markup is correct. You'll need to modify the default configuration and follow these steps: 1) Go to SVC file right click and select view markup 2) Make sure that that code behind and service pointing to correct the file and class name.


After Add this to your web.config file and configure according to your service name and contract name.

<behaviors>
   <serviceBehaviors>
      <behavior name="metadataBehavior">
         <serviceMetadata httpGetEnabled="true" />
      </behavior>
   </serviceBehaviors>
</behaviors>
<services>
   <service name="MyService.MyService" behaviorConfiguration="metadataBehavior">
      <endpoint 
          address=""   <!-- don't put anything here - Cassini will determine address -->
          binding="basicHttpBinding" 
          contract="MyService.IMyService"/>
      <endpoint 
          address="mex" 
          binding="mexHttpBinding" 
          contract="IMetadataExchange"/>
   </service>
</services>

Please add this in your Service.svc

using System.ServiceModel.Description;

Hope it will helps you.


Add Serializable() before the type you expose

Serializable()
Public Class YourType

Put Serializable into <>


I observed that when I removed SessionMode from the ServiceContract attribute, the issue went away.

Example:

[ServiceContract(SessionMode=SessionMode.Required, CallbackContract=typeof(ICallbacks))]
 public interface IStringReverser
 {
   [OperationContract]
   string ReverseString(string value);
 }

to...

[ServiceContract()]
 public interface IStringReverser
 {
   [OperationContract]
   string ReverseString(string value);
 }

For me the issue got resolved by doing the following:

Navigated to Tool --> Options --> Project and Solutions --> Web Projects

I could find the first check box "Use the 64 bit version of IIS Express of web sites and projects" was unchecked.

Selecting this check box helped me in launching the WCF Client.

VS Version : VS2019


In Visual Studio:

  1. project properties (right click on your project)
  2. Debug -> Start Options
  3. Make sure "Command line arguments" is empty

Change to older Visual Studio. Weird solution that worked for me. I was using Visual studio 2017, after changing to Visual Studio 2015 ,everything worked.


In my case, the Webservice was generating the assembly with a different name than the project/service name. It was set like that by my predecessor developer working on the solution and I didn't know.

It was set to -

  <serviceBehaviors>
    <behavior name="CustomServiceBehavior">
      <serviceAuthorization serviceAuthorizationManagerType="BookingService.KeyAuthorizationManager, BookingService" />
     </behavior>
 </serviceBehaviors>

So, the fix was the put the right assembly name in serviceAuthorizationManagerType. The assembly name can be obtained from following path of the service project: Right click on the WCF svc project--> Select "Properties" --> From the list of tabs select "Application". Check the value against "Assembly name:" field in the list. This is the assemblyName to use for serviceAuthorizationManagerType which may not be the servicename necessarily.

  <serviceBehaviors>
    <behavior name="MyCustomServiceBehavior">
      <serviceAuthorization serviceAuthorizationManagerType="BookingService.KeyAuthorizationManager, AssemblyNameFromSvcProperties" />
     </behavior>
 </serviceBehaviors>

remember to follow the instruction for serviceAuthorizationManagerType as mentioned on https://docs.microsoft.com/en-us/dotnet/framework/wcf/extending/how-to-create-a-custom-authorization-manager-for-a-service

It says -

Warning

Note that when you specify the serviceAuthorizationManagerType, the string must contain the fully qualified type name. a comma, and the name of the assembly in which the type is defined. If you leave out the assembly name, WCF will attempt to load the type from System.ServiceModel.dll.


changing the Binding Type from wsHttpbinding to basichttp binding in the endpoint tag and from wsHttpbinding to mexhttpbinginding in metadata endpoint tag helped to overcome the error. Thank you...


Most of the time this happens due to less memory space. first check then try some other tricks .


FYI - YOU CAN also get this error from a machine that is not having enough memory free. I got this error on a machine I run with 16 gigs of memory. I had a VM running with 6 gigs and a LOT of memory intensive apps. Close some down and this problem went away.

I still did get the error in the title of the question of

Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.`

I did notice a larger message about memory though in using the WCF Test Client.

Hope this helps someone else.


In my case I was getting this error because the option (HttpActivation) was not enabled. Windows features dialog box showing HTTP Activation under WCF Services under .NET Framework 4.6 Advanced Services


In my case, on commenting out the

<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/> 

in the web.config file was throwing "Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata".


Examples related to web-services

How do I POST XML data to a webservice with Postman? How to send json data in POST request using C# org.springframework.web.client.HttpClientErrorException: 400 Bad Request How to call a REST web service API from JavaScript? The request was rejected because no multipart boundary was found in springboot Generating Request/Response XML from a WSDL How to send a POST request using volley with string body? How to send post request to the below post method using postman rest client How to pass a JSON array as a parameter in URL Postman Chrome: What is the difference between form-data, x-www-form-urlencoded and raw

Examples related to wcf

Create a asmx web service in C# using visual studio 2013 WCF Exception: Could not find a base address that matches scheme http for the endpoint WCF Service, the type provided as the service attribute values…could not be found WCF error - There was no endpoint listening at How can I pass a username/password in the header to a SOAP WCF Service The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was 'NTLM' Content Type application/soap+xml; charset=utf-8 was not supported by service The content type application/xml;charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8) maxReceivedMessageSize and maxBufferSize in app.config how to generate a unique token which expires after 24 hours?