Cannot obtain Metadata from http://localhost//xxxx.svc


We were working on an issue and got the exception, since the team was not able to fix the issue mentioned below
 
"Error: Cannot obtain Metadata from http://localhost//xxxx.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//xxxx.svc  
Metadata contains a reference that cannot be resolved: 'http://localhost//xxxx.svc'.   
Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost//xxxx.svc.
'."
 
Here are some simple steps to fix the issue:
  1. Check the name of the Service in the .svc file
  2. Match it with the Service tag in the web.config if both of them don't match then you will run into these kind of issues.
  3. If these don't match then you will see the difference in the urls generated as mentioned in the screenshot below


<services>
<service behaviorConfiguration="Behavior" name="ServiceName">
<endpoint binding="basicHttpBinding" bindingConfiguration="BasicHttpBindingServer" contract="IService"/>
</service>
</services>
<client>

<endpoint address=http://xxx.xxx.xxx.xxx/xxx.svc bindingConfiguration="BasicHttpBinding"
contract="IService" name="BasicHttpBinding" />
</client >

However the fix seems to be simple but it was fun :)
 

No comments: