简体   繁体   中英

Hosting WCF service from separate dll in WCF service application

I have a WCF service in a service library and I'm trying to host it in a WCF service application. I modified the .svc file accordingly

<%@ ServiceHost Language="C#" Debug="true" Service="Mandrake.Service.OTAwareService" Factory="Mandrake.Service.OTServiceHostFactory"  %>

And I added the stuff that was originally in the service library's app config to the service application's web.config file. I thought it overrides the settings defined in the library's app.config, but it turned out if I remove the app.config file from the library and host the service application on IIS with the web.config containing the necessary endpoint setup (which worked previously) the service doesn't get started and says I have no endpoint defined.

My web.config's servicemodel section is as follows:

<system.serviceModel>

<serviceHostingEnvironment>
  <serviceActivations>
    <add service="Mandrake.Service.OTAwareService"
         factory="Mandrake.Service.OTServiceHostFactory"
         relativeAddress="OTService.svc"/>
  </serviceActivations>
</serviceHostingEnvironment>

<behaviors>
  <serviceBehaviors>
    <behavior name="StandardBehavior">
      <serviceMetadata />
      <serviceDebug includeExceptionDetailInFaults="True" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<services>
  <service name="Mandrake.Service.OTAwareService" behaviorConfiguration="StandardBehavior">
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://localhost:8062/OTService"/>
      </baseAddresses>
    </host>

    <endpoint address="" binding="netTcpBinding" name="TcpEndpoint" contract="Mandrake.Service.IOTAwareService" />
    <endpoint address="mex" binding="mexTcpBinding" name="MetadataEndpoint" contract="IMetadataExchange" />

  </service>
</services>
</system.serviceModel>

Is there a way I can host this service from the service library in my service application?

Most probably you may not have net.tcp binding enabled on website where you are hosting your service application. Check in iis if net.tcp is there in list of bindings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM