首页 文章

C#WCF MetaData endpoints 无法正常工作(IIS和ASP.NET开发服务器)

提问于
浏览
1

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

当我尝试通过浏览器访问Plate.svc的MetaData时,我得到一个400错误请求,虽然来自应用程序的好请求可以生成没有日志语句 . 来自应用程序的所有请求都正常工作

有任何想法吗?

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

  • 服务标记

  • 服务 Contract

  • 服务Web.config

  • 客户端App.config

1.服务标记

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

2.服务 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.服务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>

1 回答

  • 1

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

    关于这一点有两件事没有得到很好的记录:

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

相关问题