PDA

View Full Version : Hosting a WCF service created by the ServiceExporter



.ben
01-15-2009, 03:39 PM
What exactly do I need to do to host a service which was created by the ServiceExporter?

I think I've set up everything as it should but the problem that arrises is how to get the "output" from the exporter to the ServiceHostFactoryObject.

When I use the attributes on the classes and interfaces, so not using the exporter, I can get it running. But I want to omit the attributes, well those that can be added by the exporter, and use an approach similar to 'normal' webservice exporting.

Sample configs below.




<object id="OpcService" type="Service.OpcService, Service" singleton="false">
</object>

<object id="OpcServiceExporter" type="Spring.ServiceModel.ServiceExporter, Spring.Services">
<property name="TargetName" value="OpcService"/>
<property name="Name" value="OpcService"/>
<property name="Namespace" value="http://ServiceNamespace/"/>
<property name="ConfigurationName" value="OpcService"/>
<property name="CallbackContract" expression="T(ServiceContract.ICallback)"/>
<property name="TypeAttributes">
<list>
<object type="System.ServiceModel.ServiceBehaviorAttribute, System.ServiceModel">
<property name="ConcurrencyMode" value="Multiple"/>
<property name="InstanceContextMode" value="Single"/>
</object>
</list>
</property>

</object>

<object id="OpcServiceHost" type="Spring.ServiceModel.Activation.ServiceHostFactoryO bject, Spring.Services">
<property name="TargetName" value="OpcService" />
</object>





<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="netTcpBinding1">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="OpcService" behaviorConfiguration="DefaultBehavior">
<endpoint address="net.tcp://localhost:8000/Services/opcservice"
binding="netTcpBinding" bindingConfiguration="netTcpBinding1"
contract="ServiceContract.IOpcService" >
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8010/Services/opcservice"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DefaultBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>

.ben
01-15-2009, 04:21 PM
As i come to think of it, i probably don't need to use a hoster do I? :) will try it out later

.ben
01-16-2009, 09:04 AM
Ok, my service is running. You do need an ServiceHostFactoryObject though.

My error was that I the ConfigurationName mapped to the service definition in my app.config, which isn't the case. What is it used for then? Same counts for the 'name' property.

Bruno Baia
01-16-2009, 06:46 PM
Hi,

The Host have to reference the exporter object :



<object id="OpcServiceHost" type="Spring.ServiceModel.Activation.ServiceHostFactoryO bject, Spring.Services">
<property name="TargetName" value="OpcServiceExporter" />
</object>

instead of :


<object id="OpcServiceHost" type="Spring.ServiceModel.Activation.ServiceHostFactoryO bject, Spring.Services">
<property name="TargetName" value="OpcService" />
</object>



The ConfigurationName property is "used to locate the service element in an application configuration file. The default is the name of the service implementation class."
With Spring.NET, the default is the object's id in the configuration file.


Anyway, I will reply later this week-end as there is a code that I don't understand in ServiceExporter (line 385) :


if (!StringUtils.HasText(configurationName))
{
name = this.Interfaces[0].Name;
configurationName = this.Interfaces[0].FullName;
}



- Bruno

.ben
01-17-2009, 08:05 AM
Yes those are the changes I made to make it working.

I had looked into the source code already to try and figure it out but the description of the behaviour:


The ConfigurationName property is "used to locate the service element in an application configuration file. The default is the name of the service implementation class."
With Spring.NET, the default is the object's id in the configuration file.

isn't clear to me.

When I read that I think it means that it will look up the service node with that name in the app.config as illustrated below:

Let's say that in the exporter I give the property ConfigurationName the value "MyService", then I thought the exporter would look in the app.config for a node defined as:



<system.serviceModel>
<services>
<service name="MyService">
...
</service>
</services>
...
</system.serviceModel>


But it isn't, the exporter keeps looking for a service node with it's own id and not the ConfigurationName I've supplied.

So what does this property stand for?

Thanks for your help

Bruno Baia
01-17-2009, 01:39 PM
OK, I remember know ! :)

At first, I thought like u about the ServiceContractAttribute.ConfigurationName property and I was unable to make it work as you noticed too.

You have to use the ServiceBehaviorAttribute.ConfigurationName property :


<object id="OpcService" type="Service.OpcService, Service" singleton="false" />

<object id="OpcServiceExporter" type="Spring.ServiceModel.ServiceExporter, Spring.Services">
<property name="TargetName" value="OpcService"/>
<property name="Namespace" value="http://ServiceNamespace/"/>
<property name="CallbackContract" expression="T(ServiceContract.ICallback)"/>
<property name="TypeAttributes">
<list>
<object type="System.ServiceModel.ServiceBehaviorAttribute, System.ServiceModel">
<property name="ConfigurationName" value="OpcService"/>
<property name="ConcurrencyMode" value="Multiple"/>
<property name="InstanceContextMode" value="Single"/>
</object>
</list>
</property>
</object>

<object id="OpcServiceHost" type="Spring.ServiceModel.Activation.ServiceHostFactoryO bject, Spring.Services">
<property name="TargetName" value="OpcServiceExporter" />
</object>



<system.serviceModel>
<services>
<service name="OpcService">
...
</service>
</services>
...
</system.serviceModel>



- Bruno

nahid
01-06-2010, 02:44 PM
hi,
please let me see your client side code or configuration