我有一个胖客户端,可以在多个WCF服务上打开频道。这些服务是使用C#,WCF,nHibernate,Fluent和Unity(ServiceHostFactory)构建的。
当我尝试通过浏览器访问Plate.svc的MetaData时,我得到一个400错误的请求,虽然来自应用程序的好请求可以生成没有日志语句。来自应用程序的所有请求都能正常工作。
有什么想法吗?
我已经包含了以下文件的重要部分:
ServiceHost Language =“C#”Debug =“true”Service =“PRO.Services.PlateService”CodeBehind =“Plate.svc.cs”Factory =“PRO.Services.Configuration.UnityServiceHostFactory”
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 } }
<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>
<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>
答案 0 :(得分:1)
原来问题与使用工厂Factory =“PRO.Services.Configuration.UnityServiceHostFactory”
有关有两件事情没有得到很好的记录:
1)将ServiceHost与工厂结合使用(不是WebServiceHost) 2)您可能需要在自定义服务主机中设置MetaData端点,如Microsoft在本文中所详述:http://msdn.microsoft.com/en-us/library/aa395224.aspx