WCF Web.Config - 重复的服务名称抛出错误

时间:2015-04-04 15:26:37

标签: wcf

以下代码抛出错误

名为' service'的子元素具有相同密钥的密钥已存在于相同的配置范围内。集合元素在同一配置范围内必须是唯一的(例如,相同的application.config文件)。重复键值:' Marius.Marius_0_0_8'。

现在显然有两个名为Marius.Marius_0_0_8的服务。但是,当我尝试将其中一个的名称更改为其他内容时,我会收到不同的错误。我假设这是因为名称必须与命名空间的名称相匹配。 .svc中的课程。

我累了,已经盯着这几个小时了。我究竟做错了什么?所有我真正想做的就是打开元数据,这样我就可以连接WCF测试客户端。

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
    <system.web>
      <compilation debug="true" strict="false" explicit="true" targetFramework="4.5.1" />
      <httpRuntime targetFramework="4.5.1"  />
      <customErrors mode="Off" />
    </system.web>

    <system.serviceModel>
        <behaviors>

          <serviceBehaviors>
            <behavior name="Marius.PublishTheMetaData" >
              <!-- Add the following element to your service behavior configuration. -->
              <serviceMetadata httpGetEnabled="true" policyVersion="Policy15" />
            </behavior>
          </serviceBehaviors>

            <endpointBehaviors>
                <behavior name="Marius.MariusAspNetAjaxBehavior">
                  <webHttp/>
                </behavior>
            </endpointBehaviors>

        </behaviors>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
            multipleSiteBindingsEnabled="true" />
        <services>
            <service name="Marius.Marius_0_0_8">
                <endpoint address="" behaviorConfiguration="Marius.MariusAspNetAjaxBehavior"
                    binding="webHttpBinding" contract="Marius.Marius_0_0_8" />

            </service>

          <service name ="Marius.Marius_0_0_8" behaviorConfiguration="Marius.PublishTheMetaData">

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

        </services>

    </system.serviceModel>

</configuration>

1 个答案:

答案 0 :(得分:0)

您正在尝试为Mex端点声明另一项服务。正确的方法是只有一个服务公开两个端点:真实服务端点和wsdl端点。

<services>
        <service name="Marius.Marius_0_0_8">
            <endpoint address="" behaviorConfiguration="Marius.MariusAspNetAjaxBehavior"
                binding="webHttpBinding" contract="Marius.Marius_0_0_8" />

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

    </services>

示例:https://msdn.microsoft.com/en-us/library/ms734786(v=vs.110).aspx