gpt4 book ai didi

c# - WCF,找不到契约(Contract)名称 'IMetadataExchange'

转载 作者:太空狗 更新时间:2023-10-30 00:31:34 26 4
gpt4 key购买 nike

我只是应用本文中的代码,

http://msdn.microsoft.com/en-us/library/ms733766(v=vs.110).aspx

我没有做任何更改,但是从 IIS 浏览后我得到了

The contract name 'IMetadataExchange' could not be found in the list of contracts implemented by the service CalculatorService.  Add a ServiceMetadataBehavior to the configuration file or to the ServiceHost directly to enable support for this contract

可能有什么问题,我按照链接做了。我寻找答案。我可以通过添加

来处理
  <behaviors>
<serviceBehaviors>
<behavior name="CalculatorServiceBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>

但我不想添加这个,因为在查看链接时 msdn 没有添加。错误是什么?

这是我的配置文件:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="Microsoft.ServiceModel.Samples.CalculatorService">

<!-- This endpoint is exposed at the base address provided by host: http://localhost/servicemodelsamples/service.svc -->
<endpoint address=""
binding="wsHttpBinding"
contract="Microsoft.ServiceModel.Samples.ICalculator" />

<!-- The mex endpoint is explosed at http://localhost/servicemodelsamples/service.svc/mex -->
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>

</configuration>

最佳答案

如果要自学,请尝试删除以下语句,然后再次检查您的服务。

<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

最后 Web.config 文件看起来像这样来完成它。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<!-- This section is optional with the default configuration
model introduced in .NET Framework 4 -->
<service name="Microsoft.ServiceModel.Samples.CalculatorService" behaviorConfiguration="MyServiceTypeBehaviors">

<!-- This endpoint is exposed at the base address provided by host: http://localhost/servicemodelsamples/service.svc -->
<endpoint address=""
binding="wsHttpBinding"
contract="Microsoft.ServiceModel.Samples.ICalculator" />

<!-- The mex endpoint is exposed at http://localhost/servicemodelsamples/service.svc/mex -->
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors" >
<!-- Add the following element to your service behavior configuration. -->
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>

</configuration>

关于c# - WCF,找不到契约(Contract)名称 'IMetadataExchange',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24874859/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com