C# WCF 元数据端点不工作(IIS 和 ASP.NET 开发服务器)

发布于 2024-11-18 22:19:54 字数 3618 浏览 4 评论 0原文

我有一个胖客户端,它在多个 WCF 服务上打开通道。这些服务是使用 C#、WCF、nHibernate、Fluent 和 Unity (ServiceHostFactory) 构建的。

当我尝试通过浏览器访问 Plate.svc 的元数据时,我收到 400 错误请求,该请求不会生成日志语句,尽管来自应用程序的良好请求会生成日志语句。来自应用程序的所有请求都正常工作。

有什么想法吗?

我已包含以下文件的重要部分:

  1. 服务标记
  2. 服务合同
  3. 服务 Web.config
  4. 客户端 App.config

1. 服务标记

ServiceHost Language="C#" Debug="true" Service="PRO.Services.PlateService" CodeBehind= "Plate.svc.cs" Factory="PRO.Services.Configuration.UnityServiceHostFactory"

2. 服务合同

namespace PRO.ServiceContracts {
    [ServiceContract]
    public interface IPlateService {
        [OperationContract]
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        [FaultContract(typeof(string))]
        AnalysisPlate Search(string barcode);

        // identically defined operations removed
    }
}

3. 服务 Web.config

   <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpEndpointBinding">
          <security mode="None">
            <transport clientCredentialType="None" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ProBehavior">
          <serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
    <services>
      <service behaviorConfiguration="ProBehavior" name="PRO.Services.PlateService">
        <endpoint address="" contract="PRO.ServiceContracts.IPlateService"
                  binding="basicHttpBinding" bindingConfiguration="BasicHttpEndpointBinding"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
      <service behaviorConfiguration="ProBehavior" name="PRO.Services.SampleService">
        <endpoint address="" contract="PRO.ServiceContracts.ISampleService" 
                  binding="basicHttpBinding" bindingConfiguration="BasicHttpEndpointBinding"/>
      </service>
    </services>
   </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
    </modules>
  </system.webServer>

4. 客户端 App.config

 <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_Normal">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:4829/Sample.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Normal" contract="PRO.ServiceContracts.ISampleService" name="DEV_ISampleService" />
      <endpoint address="http://localhost:4829/Plate.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Normal" contract="PRO.ServiceContracts.IPlateService" name="DEV_IPlateService" />
    </client>
  </system.serviceModel>

I have a thick client which opens channels on several WCF services. The services are built using C#, WCF, nHibernate, Fluent and Unity (ServiceHostFactory).

When I try to access the MetaData for Plate.svc through the browser I get a 400 bad request which generates no log statements although the good requests from the app do. All requests from the app work normally.

Any ideas?

I've included the important bits of the following files:

  1. Service markup
  2. Service Contract
  3. Service Web.config
  4. Client App.config

1. Service Markup

ServiceHost Language="C#" Debug="true" Service="PRO.Services.PlateService" CodeBehind="Plate.svc.cs" Factory="PRO.Services.Configuration.UnityServiceHostFactory"

2. Service Contract

namespace PRO.ServiceContracts {
    [ServiceContract]
    public interface IPlateService {
        [OperationContract]
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        [FaultContract(typeof(string))]
        AnalysisPlate Search(string barcode);

        // identically defined operations removed
    }
}

3. Service Web.config

   <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpEndpointBinding">
          <security mode="None">
            <transport clientCredentialType="None" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ProBehavior">
          <serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
    <services>
      <service behaviorConfiguration="ProBehavior" name="PRO.Services.PlateService">
        <endpoint address="" contract="PRO.ServiceContracts.IPlateService"
                  binding="basicHttpBinding" bindingConfiguration="BasicHttpEndpointBinding"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
      <service behaviorConfiguration="ProBehavior" name="PRO.Services.SampleService">
        <endpoint address="" contract="PRO.ServiceContracts.ISampleService" 
                  binding="basicHttpBinding" bindingConfiguration="BasicHttpEndpointBinding"/>
      </service>
    </services>
   </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
    </modules>
  </system.webServer>

4. Client App.config

 <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_Normal">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:4829/Sample.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Normal" contract="PRO.ServiceContracts.ISampleService" name="DEV_ISampleService" />
      <endpoint address="http://localhost:4829/Plate.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Normal" contract="PRO.ServiceContracts.IPlateService" name="DEV_IPlateService" />
    </client>
  </system.serviceModel>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最偏执的依靠 2024-11-25 22:19:54

事实证明,问题与使用工厂 Factory="PRO.Services.Configuration.UnityServiceHostFactory" 有关,

有两件事没有得到很好的记录:

1) 将 ServiceHost 与工厂结合使用(不是 WebServiceHost)
2) 您可能需要在自定义服务主机中设置元数据端点,如 Microsoft 的这篇文章中所述:http://msdn.microsoft.com/en-us/library/aa395224.aspx

Turns out the problem was related to using a factory Factory="PRO.Services.Configuration.UnityServiceHostFactory"

There are two things about this that haven't been well documented:

1) Use a ServiceHost in conjunction with your factory (not a WebServiceHost)
2) You will probably need to setup your MetaData endpoints in the custom service host as detailed in this post by Microsoft: http://msdn.microsoft.com/en-us/library/aa395224.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文