Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.`
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.