繁体   English   中英

WCF Web.Config中的C#多种服务

[英]C# Multiple Services in WCF Web.Config

我试图在我的web.config文件中启用多个WCF服务,但是由于某种原因,我遇到以下错误。

Metadata publishing for this service is currently disabled.

一切对我来说都不错。 这是来自web.config的服务模型。 我在网上搜索并遵循了这些方法,但奇怪的是,它对我不利。

<system.serviceModel>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true">
    </serviceHostingEnvironment>

    <bindings>
      <basicHttpBinding>
        <binding name="basicHttpBindingConfig">
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>


    <services>
      <!-- Note: the service name must match the configuration name for the service implementation. -->
      <service name="ProductDataService" behaviorConfiguration="ProductDataServiceBehavior">
        <!-- Add the following endpoint.  -->
        <!-- Note: your service must have an http base address to add this endpoint. -->
        <endpoint
            address="http://api.xxx.com/services/Product.svc"
            binding="basicHttpBinding"
            bindingConfiguration="basicHttpBindingConfig"
            contract="ProductDataService" />
        <endpoint address="mex"
            binding="mexHttpsBinding"
            contract="IMetadataExchange" />
      </service>

      <service name="MediaContentService" behaviorConfiguration="MediaContentServiceBehavior">
        <!-- Add the following endpoint.  -->
        <!-- Note: your service must have an http base address to add this endpoint. -->
        <endpoint
            address="http://api.xxx.com/services/Media.svc"
            binding="basicHttpBinding"
            bindingConfiguration="basicHttpBindingConfig"
            contract="MediaContentService" />
        <endpoint address="mex"
            binding="mexHttpsBinding"
            contract="IMetadataExchange" />
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="ProductDataServiceBehavior" >
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" externalMetadataLocation="http://api.xxx.com/wsdl/ProductDataService.wsdl"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
        <behavior name="MediaContentServiceBehavior" >
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" externalMetadataLocation="http://api.xxx.com/wsdl/MediaContentService.wsdl"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

编辑

即使我只添加1个服务,它也会中断。 仅在为行为添加名称时才会发生。 这是仅配置了1个服务的服务模型。

<system.serviceModel>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true">
    </serviceHostingEnvironment>

    <bindings>
      <basicHttpBinding>
        <binding name="basicHttpBindingConfig">
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>


    <services>
      <!-- Note: the service name must match the configuration name for the service implementation. -->
      <service name="ProductDataService" >
        <!-- Add the following endpoint.  -->
        <!-- Note: your service must have an http base address to add this endpoint. -->
        <endpoint
            address="http://api.xxx.com/services/Product.svc"
            binding="basicHttpBinding"
            bindingConfiguration="basicHttpBindingConfig"
            contract="ProductDataService" />
        <endpoint address="mex"
            binding="mexHttpsBinding"
            contract="IMetadataExchange" />
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" externalMetadataLocation="http://api.xxx.com/wsdl/ProductDataService.wsdl"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

  </system.serviceModel>

您可以检查服务名称吗

 namespace MyNameSpace
 {
   .....
    public class MyClass: IInterface
    {

config中标签上的name =属性必须与您的服务类完全相同-完全合格,包括名称空间-因此,在这里,您应该是:

  <service name="MyNameSpace.MyClass" ......>

另外,您使用mexHttp Binding,所以使用http GetEnabled。 (您的配置中缺少“”)

在将完整名称空间添加到服务名称并将完整名称空间添加到协定之后,然后需要使端点地址相对。 以下是我的完整解决方案。 对于服务'Proactive_WebAPI.Services.Media',然后合同给出了错误,因此从其中删除了名称空间,并且一切正常。

<system.serviceModel>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true">
    </serviceHostingEnvironment>

    <bindings>
      <basicHttpBinding>
        <binding name="basicHttpBindingConfig">
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>


    <services>
      <!-- Note: the service name must match the configuration name for the service implementation. -->
      <service name="Proactive_WebAPI.Services.Product"  behaviorConfiguration="ProductDataServiceBehavior">
        <!-- Add the following endpoint.  -->
        <!-- Note: your service must have an http base address to add this endpoint. -->
        <endpoint
            address="Product.svc"
            binding="basicHttpBinding"
            bindingConfiguration="basicHttpBindingConfig"
            contract="Proactive.Product.ProductDataService" />
      </service>
      <service name="Proactive_WebAPI.Services.Media"  behaviorConfiguration="MediaContentServiceBehavior">
        <!-- Add the following endpoint.  -->
        <!-- Note: your service must have an http base address to add this endpoint. -->
        <endpoint
            address="Media.svc"
            binding="basicHttpBinding"
            bindingConfiguration="basicHttpBindingConfig"
            contract="MediaContentService" />
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="ProductDataServiceBehavior" >
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" externalMetadataLocation="http://api.xxx.com/wsdl/ProductDataService.wsdl"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      <behavior name="MediaContentServiceBehavior" >
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" externalMetadataLocation="http://api.xxx.com/wsdl/MediaContentService.wsdl"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

  </system.serviceModel>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM