WCF 和 Spring.nets ServiceExporter
有人成功使用 spring.nets Spring.ServiceModel.ServiceExporter 和 WCF 吗?
一些背景.....
我正在尝试使用 spring.net 配置 wcf 服务以在 Web 应用程序中使用在
项目的第一次迭代中,我通过使用 spring 配置服务对象(我给了它 id requestManagerService)并成功了在 svc 文件中,我将 springs ServiceHostFactory 指向该对象。 svc 文件看起来像这样:
<%@ ServiceHost Language="C#" Debug="true" Service="requestManagerService" Factory="Spring.ServiceModel.Activation.ServiceHostFactory" %>
但是我不想用 [ServiceContract] 和 [OperationContract] 属性来装饰我的接口/合约。为了避免这种情况,您可以使用 springs ServiceExporter。
因此,我在 Web 配置中进行了以下设置:
<object id="requestManagerService" type="SupplyAndDemand.Messaging.UI.Web.RequestManagerService, SupplyAndDemand.Messaging.UI.Web"
singleton="false">
</object>
<system.serviceModel>
<services>
<service name="requestManagerService" behaviorConfiguration="DefaultBehavior">
<endpoint address="" binding="basicHttpBinding" contract="SupplyAndDemand.Shared.Interfaces.Services.IRequestManagerService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DefaultBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<object id="requestManagerServiceHost" type="Spring.ServiceModel.Activation.ServiceHostFactoryObject, Spring.Services">
<property name="TargetName" value="requestManagerServiceExporter" />
</object>
<object id="requestManagerServiceExporter" type="Spring.ServiceModel.ServiceExporter, Spring.Services">
<!-- The target object to export-->
<property name="TargetName" value="requestManagerService"/>
<!-- The namespace associated with the wcf service-->
<property name="Namespace" value="http://supplyanddemandapp/"/>
<property name="TypeAttributes">
<list>
<object type="System.ServiceModel.ServiceBehaviorAttribute, System.ServiceModel">
<property name="ConfigurationName" value="requestManagerService"/>
</object>
</list>
</property>
</object>
当我运行 Web 应用程序时,出现以下错误:
“无法找到与绑定 BasicHTTPBinding 的端点的方案 http 相匹配的基地址。已注册的基地址方案是 []”此错误发生在 System.ServiceModel.ServiceHostBase.MakeAbsoluteUri 中)。
显然,这意味着我需要定义一个基地址......但我相信我的问题是配置 spring 而不是 WCF,因为我使用的是 wcf 配置,它以前在我不使用导出器时工作。
spring 文档暗示配置很简单,我确信我正在做一些根本错误的事情 - 有人成功地将 ServiceExporter 与 asp.net Web 应用程序一起使用吗?
Has anybody successfully using spring.nets Spring.ServiceModel.ServiceExporter with WCF??
Some background.....
I'm trying to configure wcf services with spring.net for use in a web application
In my first iteration of the project I suceeded by configuring the service object with spring (I gave it the id requestManagerService) and in the svc file I pointed springs ServiceHostFactory at this object. The svc file looked like this:
<%@ ServiceHost Language="C#" Debug="true" Service="requestManagerService" Factory="Spring.ServiceModel.Activation.ServiceHostFactory" %>
However I do not want to decorate my interface/contract with [ServiceContract] and [OperationContract] attributes. To avoid this you can use springs ServiceExporter.
So I have set up the following in my web config:
<object id="requestManagerService" type="SupplyAndDemand.Messaging.UI.Web.RequestManagerService, SupplyAndDemand.Messaging.UI.Web"
singleton="false">
</object>
<system.serviceModel>
<services>
<service name="requestManagerService" behaviorConfiguration="DefaultBehavior">
<endpoint address="" binding="basicHttpBinding" contract="SupplyAndDemand.Shared.Interfaces.Services.IRequestManagerService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DefaultBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<object id="requestManagerServiceHost" type="Spring.ServiceModel.Activation.ServiceHostFactoryObject, Spring.Services">
<property name="TargetName" value="requestManagerServiceExporter" />
</object>
<object id="requestManagerServiceExporter" type="Spring.ServiceModel.ServiceExporter, Spring.Services">
<!-- The target object to export-->
<property name="TargetName" value="requestManagerService"/>
<!-- The namespace associated with the wcf service-->
<property name="Namespace" value="http://supplyanddemandapp/"/>
<property name="TypeAttributes">
<list>
<object type="System.ServiceModel.ServiceBehaviorAttribute, System.ServiceModel">
<property name="ConfigurationName" value="requestManagerService"/>
</object>
</list>
</property>
</object>
When I run the web application I get the following error:
"Could not find a base address that matches scheme http for the endpoint with binding BasicHTTPBinding. Registered base adress schemes are []" This error occurs in System.ServiceModel.ServiceHostBase.MakeAbsoluteUri).
Obviously this implies that I need to define a base address.... but I belive my problem is in configuring spring rather than WCF since I am using wcf config which previously worked when I didnt use the exporter.
The spring docs imply configuration is simple and I'm convinced I'm doing something fundamentally wrong - has anybody successfully used the ServiceExporter with an asp.net web app?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定你的问题是否解决了,但我也遇到了类似的问题。但是,我使用的是 wsHttpBinding。话虽这么说,除了 BennyM 的建议之外,我还必须删除以下对象:
它仅用于独立应用程序。
Not sure if you resolved your issue, but I was having a similar one. However, I was using wsHttpBinding. That being said, in addition to BennyM's recommendations, I had to remove the following object:
It is used for standalone applications only.
ServiceExporter 是一个工厂对象。在这种情况下,它将创建一个包装 requestManagerService 的对象并添加必要的属性。您需要在 WCF 配置中使用此对象,而不是原始的 requestManagerService。
因此,为了使其与此处显示的配置一起使用,您需要将
Svc 文件:
Web.config:
任何其他DI或AoP配置,只需使用原始的requestManagerService即可。
The ServiceExporter is a factory object. In this case it will create an object that wraps the requestManagerService and adds the necessary attributes. It's this object you need to use in your WCF configuration and not the original requestManagerService.
So in order to make this work with the configuration you've shown here you need to
Svc File:
Web.config:
Any other DI or AoP config, just use the original requestManagerService.