WCF Test Client cannot add service, cannot obtain metadata

依然范特西╮ 提交于 2019-11-27 03:20:42

问题


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>

回答1:


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"




回答2:


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
{
  ....
}



回答3:


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.




回答4:


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\




回答5:


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




回答6:


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.




回答7:


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



回答8:


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.




回答9:


In my case, I had not enabled BindingParams.AllowHttpGet. When that was set to true, it worked...




回答10:


please check and read all text of error.

in my case another dll has error but show same error in above text of error.




回答11:


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.



来源:https://stackoverflow.com/questions/9114870/wcf-test-client-cannot-add-service-cannot-obtain-metadata

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!