Reputation: 1810
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"
binding="mexHttpBinding"
name="Metadata"
contract="IMetadataExchange" />
I also have the service behaviors set:
<serviceBehaviors>
<behavior name="myBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
Upvotes: 13
Views: 66174
Reputation: 3816
Please check that you can resolve that address and that you have specified the correct virtual directory. Does myserver resolve to an IP with forexample ping myserver? Is myapp the correct virtual directory? You have enabled metadata for your wcf service, but the url is most likely wrong.
Upvotes: 0
Reputation: 1901
please check and read all text of error.
in my case another dll has error but show same error in above text of error.
Upvotes: 0
Reputation: 1730
In my case, I had not enabled BindingParams.AllowHttpGet. When that was set to true, it worked...
Upvotes: 0
Reputation: 1810
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.
Upvotes: 5
Reputation: 943
This can also happen when you try to return a custom class object from one of the functions and that function doesn't have the [DataContract]
attribute on the class declaration. WCF cant figure out what type your returning so it throws the standard message.
[Serializable]
[DataContract]
public class ServiceResult
{
....
}
Upvotes: 9
Reputation: 957
This is my experience on this error message,might be useful to others. My WCF service is working fine on windows 2008 server.I copied the same solution to Dev machine, selected .svc file from solution so that WCF test client can be popped-up.
WCF test client opened with errors cannot obtain metadata,assembly can't be loaded etc.
Key is, first kick up the service (http://localhost:port/Service) then only try WCF test client.
Upvotes: 0
Reputation: 741
I discovered that I had the same error because of a DataContract that I was using that inherited from Dictionary. The proper setup of the DataContract should be as follows:
[CollectionDataContract(Name = "AdditionalProperties",
ItemName = "Property",
KeyName = "Key",
ValueName = "Value")]
public class AdditionalProperties : Dictionary<string, string>
{
}
Upvotes: 0
Reputation: 1725
I had this issue, turns out that when I renamed the .svc file a reference to it hadn't been renamed from Service1.svc. Run a project wide search and replace .Service1
with your new name.
<%@ ServiceHost Language="C#" Debug="true" Service="MyNamespace.Service1" CodeBehind="MyRenamedService.svc.cs" %>
Service="MyNamespace.Service1"
should read Service="MyNamespace.MyRenamedService"
Upvotes: 10
Reputation: 828
Some times there isn't anything to be done with metadata or the settings; instead we may simply use 127.0.0.1 instead of http:\localhost\
Upvotes: 1
Reputation: 91
I'm new to WCF and just got a project handed to me with WCF services inside. I was having similar issues with using WCF Test Client in VS2010 on Win7. After trying all the config changes in this article and others I was still getting similar errors.
So I gave up and started reading up on WCF. Here I found that VS should be launched as administrator. Here's the article: Getting Started Tutorial WCF Turns out I have to launch VS2010 with 'Run as Administrator' checked. This fixed the issue and I was able to test WCF services in VS2010. I'm posting this answer incase others over look the Run as Administrator.
Upvotes: 0
Reputation:
If adding the metadata endpoints is not your issue. Check further in the error message details. I had a missing library; "Could not load file or assembly *".
I needed to change the reference to Copy Local = True
Upvotes: 0