hyprsleepy hyprsleepy - 2 months ago 40
C# Question

WCF Test Client cannot add service, cannot obtain metadata

Can anyone tell me why I get this error when I try to add my service?

Error: Cannot obtain Metadata from http://myserver/myapp. 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://myserver/myapp Metadata contains a reference that cannot be resolved: 'http://myserver/myapp'. The remote server returned an unexpected response: (405) Method Not Allowed.
The remote server returned an error: (405) Method Not Allowed.HTTP GET Error URI: http://myserver/myapp There was an error downloading 'http://myserver/myapp'. The request failed with HTTP status 403: Forbidden.

Update: I have the following endpoint already,

<endpoint address="mex"
contract="IMetadataExchange" />

I also have the service behaviors set:

<behavior name="myBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />


I figured it out. I was using an absolute path on one of my endpoints and I had more than one. I changed it to a relative path and then everything worked.

Also, this can happen if your service isn't running and may have nothing to do with metadata. If you have a ConfigurationErrorsException then you will see this result as well.

I also got it when trying to save configuration changes to the project and then it told me to save/overwrite/ignore, etc. It ended up adding a project subtype of "designer" and once I removed that it went back to working properly.