WCF cannot configure WSDL publishing

六月ゝ 毕业季﹏ 提交于 2019-12-12 05:39:24

问题


I want to enable WSDL retrieval for a webservice that I created. I can 'call' the webservice through the .svc file that I made:

http://localhost/test.svc

<%@ ServiceHost Language="C#" Debug="true" Service="Project.MyService" CodeBehind="MyService.svc.cs" %>

Calling the page gives the standard .NET message saying "Metadata publishing for this service is currently disabled." with instructions to enable publishing.

I followed instructions and added the web.config entries, however calling http://localhost/test.svc?wsdl produces the same result... How can I enable WSDL publishing for my webservice?

web.config entries

  <service name="Project.IMyService" behaviorConfiguration="MyServiceTypeBehaviors" >
    <endpoint contract="IMetadataExchange" binding="mexHttpBinding" 
              address="mex"
              />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost/test.svc"/>
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="MyServiceTypeBehaviors">
      <serviceMetadata httpGetEnabled="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>


回答1:


Sounds crazy but just remove behaviorConfiguration="MyServiceTypeBehaviors" from the service definition andlet the behavior anonymous (with no name). It will remain

<services>
     <service name="WcfServiceLibrary1.IMyService" >
    <endpoint contract="IMetadataExchange" binding="mexHttpBinding" 
              address="mex"
              />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost/test.svc"/>
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior >
      <serviceMetadata httpGetEnabled="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>



回答2:


The mex endpoint and httpGetEnabled look ok. This link covers the topic in some more detail and may be of use.

http://msdn.microsoft.com/en-us/library/ms788760.aspx



来源:https://stackoverflow.com/questions/8861508/wcf-cannot-configure-wsdl-publishing

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