Results 1 to 7 of 7

Thread: Hosting a WCF service created by the ServiceExporter

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Belgium
    Posts
    213

    Default Hosting a WCF service created by the ServiceExporter

    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.

    Code:
    	<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.ServiceHostFactoryObject, Spring.Services">
    		<property name="TargetName" value="OpcService" />
    	</object>
    Code:
    	<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>

  2. #2
    Join Date
    Oct 2005
    Location
    Belgium
    Posts
    213

    Default

    As i come to think of it, i probably don't need to use a hoster do I? will try it out later

  3. #3
    Join Date
    Oct 2005
    Location
    Belgium
    Posts
    213

    Default

    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.

  4. #4
    Join Date
    Oct 2005
    Location
    Toulouse, France
    Posts
    1,407

    Default

    Hi,

    The Host have to reference the exporter object :

    Code:
    <object id="OpcServiceHost" type="Spring.ServiceModel.Activation.ServiceHostFactoryObject, Spring.Services">
       <property name="TargetName" value="OpcServiceExporter" />
    </object>
    instead of :
    Code:
    <object id="OpcServiceHost" type="Spring.ServiceModel.Activation.ServiceHostFactoryObject, 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) :
    Code:
    if (!StringUtils.HasText(configurationName))
    {
        name = this.Interfaces[0].Name;
        configurationName = this.Interfaces[0].FullName;
    }

    - Bruno
    My english is as poor as my taylor is rich

  5. #5
    Join Date
    Oct 2005
    Location
    Belgium
    Posts
    213

    Default

    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:

    Code:
    <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

  6. #6
    Join Date
    Oct 2005
    Location
    Toulouse, France
    Posts
    1,407

    Default

    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 :
    Code:
    <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.ServiceHostFactoryObject, Spring.Services">
      <property name="TargetName" value="OpcServiceExporter" />
    </object>
    Code:
    <system.serviceModel>
        <services>
          <service name="OpcService">
                 ...
          </service>
        </services>
         ...    
    </system.serviceModel>

    - Bruno
    My english is as poor as my taylor is rich

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •