【问题标题】:App.config namespace issueApp.config 命名空间问题
【发布时间】:2009-10-19 01:56:27
【问题描述】:

我正在使用由 wsdl 生成的接口,并且在尝试将我的服务托管为 Windows 服务时遇到了问题。

下面一行出现在界面上方。除非我把它改成

    [System.ServiceModel.ServiceContractAttribute(Namespace="http://xxxxxx.com/", ConfigurationName="IService")]

    [System.ServiceModel.ServiceContract]

我无法启动托管我的程序的 Windows 服务(事件查看器中的错误日志显示在 Service 实施的合同列表中找不到合同 IService。)我正在列出我的应用程序的端点。配置文件如下:

   endpoint address=""
              binding="basicHttpBinding"
              contract="Service.IService"

当我将合同更改为“http://xxxxxxx.com/IService”时也会发生这种情况,因为它出现在 ServiceContractAttribute 中。关于如何解决此问题的任何想法?

配置文件的服务部分:

<service name="Service.Service"
           behaviorConfiguration="myServiceBehavior">
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8000/Service"/>
      </baseAddresses>
    </host>
    <endpoint address=""
              binding="basicHttpBinding"
              contract="Service.IService" />
    <endpoint address="mex"
              binding="mexHttpBinding"
              contract="Service.IService" />

  </service>
<behaviors>
  <serviceBehaviors>
    <behavior name="myServiceBehavior">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="True"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

【问题讨论】:

  • 这听起来不像是端点配置问题,而是服务配置问题。您的属性提到了 ConfigurationName="IService":您可以发布 app.config 元素的 name="IService" 吗?

标签: c# .net wcf


【解决方案1】:

config中endpoint元素的contract属性需要和代码中ServiceContractAttribute的ConfigurationName属性的值相匹配。因此,在您的情况下,只需更改配置,使其显示为 contract="IService" 就可以了。

【讨论】:

  • 这允许服务启动,但是当客户端尝试使用该服务时,我遇到了不同的问题。是时候提出一个新问题了!
【解决方案2】:

似乎找不到端点。您是否使用终端询问端点以查看它是否在提供的地址响应?

【讨论】:

    【解决方案3】:

    “itowlson”的评论很可能走在正确的轨道上 - 您的原始服务合同定义了一个配置名称:

    [ServiceContract(Namespace="http://xxxxxx.com/", 
                     ConfigurationName="IService")]
    

    但是你的配置部分没有这样的服务配置。

    尝试改变这个:

    <service name="Service.Service"
    

    <service name="IService"
    

    (或者,将 ServiceContract 更改为:

    [ServiceContract(Namespace="http://xxxxxx.com/", 
                     ConfigurationName="Service.Service")]
    

    这两个名字需要匹配!或者干脆从服务合同中省略配置名称:

    [ServiceContract(Namespace="http://xxxxxx.com/")]
    

    在这种情况下,将根据实际实现服务契约的服务类的Namespace.ServiceClassName 模式找到服务配置。

    无论哪种方式,您都需要确保ServiceContract 属性中的信息与配置文件匹配。

    马克

    【讨论】:

    • 即使 ConfigurationName 和“
    猜你喜欢
    • 2011-02-05
    • 2013-03-26
    • 2016-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    • 2011-04-11
    相关资源
    最近更新 更多