C# WCF 元数据端点不工作(IIS 和 ASP.NET 开发服务器)
我有一个胖客户端,它在多个 WCF 服务上打开通道。这些服务是使用 C#、WCF、nHibernate、Fluent 和 Unity (ServiceHostFactory) 构建的。
当我尝试通过浏览器访问 Plate.svc 的元数据时,我收到 400 错误请求,该请求不会生成日志语句,尽管来自应用程序的良好请求会生成日志语句。来自应用程序的所有请求都正常工作。
有什么想法吗?
我已包含以下文件的重要部分:
- 服务标记
- 服务合同
- 服务 Web.config
- 客户端 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:
- Service markup
- Service Contract
- Service Web.config
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,问题与使用工厂 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