WCF无法配置WSDL发布 [英] WCF cannot configure WSDL publishing

查看:137
本文介绍了WCF无法配置WSDL发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要为我创建的webservice启用WSDL检索。我可以通过我做的.svc文件调用webservice:



http://localhost/test.svc

 <%@ ServiceHost Language =C#Debug =trueService =Project.MyServiceCodeBehind =MyService.svc。 cs%> 

调用页面会显示标准的.NET消息:此服务的元数据发布当前已禁用。 svc?wsdlrel =nofollow> http://localhost/test.svc?wsdl 产生相同的结果...如何为我的webservice启用WSDL发布?



web.config条目




 < service name =Project.IMyServicebehaviorConfiguration =MyServiceTypeBehaviors> 
< endpoint contract =IMetadataExchangebinding =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>

解决方案

听起来很疯狂,但只是从服务定义中删除behaviorConfiguration =MyServiceTypeBehaviorsandlet行为匿名(没有名称)。

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


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>

解决方案

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>

这篇关于WCF无法配置WSDL发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆