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 na开发者_开发知识库me="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>
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
)
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.
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.
Add Serializable()
before the type you expose
Serializable()
Public Class YourType
Put Serializable
into <>
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...
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...
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".
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
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);
}
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.
Most of the time this happens due to less memory space. first check then try some other tricks .
The property IsOneWay=true
may be true in the Operational contract of the interface.
Remove that property to get rid of this error.
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://learn.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.
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 Visual Studio:
- project properties (right click on your project)
- Debug -> Start Options
- Make sure "Command line arguments" is empty
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.
I had that issue. The solution is to startup VS with administrative privilege.
精彩评论