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="IMeta开发者_开发问答dataExchange"/>
</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?
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:
<object id="requestManagerServiceHost" type="Spring.ServiceModel.Activation.ServiceHostFactoryObject, Spring.Services">
<property name="TargetName" value="requestManagerServiceExporter" />
</object>
It is used for standalone applications only.
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
- change the name of the service in the .svc file to requestManagerServiceExporter
- change the name of the service in the to requestManagerServiceExporter
Svc File:
<%@ ServiceHost Language="C#" Debug="true" Service="requestManagerServiceExporter" Factory="Spring.ServiceModel.Activation.ServiceHostFactory" %>
Web.config:
<system.serviceModel>
<services>
<service name="requestManagerServiceExporter" 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>
Any other DI or AoP config, just use the original requestManagerService.
精彩评论