Hosting the same WCF Service in IIS and in Windows Service - windows

I am trying to decide on an architecture for a change in my web service. I need to make a WCF service. I want to make only one service and then host it either in the IIS or in a Windows service. Is this even possible, making this kind of reuse of a WCF Service? How would I go about doing this? The scenario is that some of our customers do not have access to start a Windows service but can install a WCF in the IIS.
Thank you in advance.

A WCF service is simply an assembly that abides by the WCF hosting interface and then provides a client interface that allows it to be accessed.
Hosting a WCF service occurs equally in IIS, Windows service, WinForm application, or a console application. It truly doesn't matter.
The client interface remains unchanged, although how the interface is exposed might change depending on hosting scenario. For example, you'll probably use one the http bindings in the IIS case, but might use TCP binding for Windows services. These bindings can be defined in the config file, so the code doesn't necessarily have to change to accommodate being hosted one way or the other.
In short, creating the WCF service should be independent of how it will eventually be hosted. For ease of maintenance on your part, though, I'd pick one or the other - Windows service or IIS.

you could have a windows service host the WCF and expose all end points on it..Http,TCP..
Windows service is better than IIS because IIS is a process in itself and then we place upon it a VD to host our website/WCF.As for the Windows Service,it will be one dedicated thread catering only to the WCF.I am sharing the app.config of windows service (details changed) to show how we have hosted WCF...hope it helps..
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Off" propagateActivity="true" >
<listeners>
<add name="SERVICE_MONITOR" type="System.Diagnostics.XmlWriterTraceListener"
initializeData="MyApp_MONITOR.svclog" />
</listeners>
</source>
<source name="MyApp_TRACE" switchValue="All" >
<listeners>
<add name="MyApp_TRACE_LISTENER" type="System.Diagnostics.XmlWriterTraceListener"
initializeData="MyApp_TRACE.svclog" />
</listeners>
</source>
</sources>
<trace autoflush="true" />
</system.diagnostics>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="OverAllServiceBehavior">
<serviceSecurityAudit
auditLogLocation="Application"
serviceAuthorizationAuditLevel="Failure"
messageAuthenticationAuditLevel="Failure"
suppressAuditFailure="true" />
<serviceDebug includeExceptionDetailInFaults="True" />
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
<serviceThrottling maxConcurrentCalls="10000" maxConcurrentSessions="10000"
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceCredentials>
<userNameAuthentication
userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="MyAppHost.Authenticate, MyAppHost"/>
<serviceCertificate findValue="MyApp_MESSAGE" storeLocation="LocalMachine"
storeName="My" x509FindType="FindBySubjectName" />
<clientCertificate>
<authentication
certificateValidationMode="PeerTrust"
trustedStoreLocation="LocalMachine" />
</clientCertificate>
</serviceCredentials>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="OverAllEndPointBehavior" />
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="ServiceBasicHttpEndPointBinding" closeTimeout="00:00:59"
openTimeout="00:00:59"
messageEncoding="Text"
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="Message">
<message clientCredentialType="Certificate"/>
</security>
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="ServiceWSHttpEndPointBinding" closeTimeout="00:00:59"
openTimeout="00:00:59"
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None" />
<message clientCredentialType="Certificate"/>
</security>
</binding>
</wsHttpBinding>
<netTcpBinding>
<binding name="ServiceTCPEndPointBinding" maxBufferSize="2147483647"
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="TransportWithMessageCredential">
<transport
clientCredentialType="Certificate"
protectionLevel="EncryptAndSign" />
<message clientCredentialType="UserName" algorithmSuite="TripleDes"/>
</security>
</binding>
</netTcpBinding>
</bindings>
<services>
<service behaviorConfiguration="OverAllServiceBehavior"
name="MiddleWare.ServiceClasses.ServiceClass">
<host>
<baseAddresses>
<add baseAddress="net.tcp://127.0.0.1:15010/ServiceTCPEndPointMEX"/>
<add baseAddress="http://127.0.0.1:15020/ServiceHttpEndPointMEX"/>
<add baseAddress="https://127.0.0.1:15030/ServiceWSHttpEndPointMEX"/>
</baseAddresses>
</host>
<endpoint address="net.tcp://127.0.0.1:15040/ServiceTCPEndPoint"
contract="MiddleWare.ServiceContracts.IServiceContract" />
<endpoint address="http://127.0.0.1:15050/ServiceBasicHttpEndPoint"
contract="MiddleWare.ServiceContracts.IServiceContract"/>
<endpoint address="https://127.0.0.1:15060/ServiceWSHttpEndPoint"
contract="MiddleWare.ServiceContracts.IServiceContract"/>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
<appSettings>
<add key="UserName" value="USER"/>
<add key="Password" value="PASSWORD"/>
</appSettings>
</configuration>

Related

publishing web service on 3 different IIS gets different result,Metadata publishing for this service is currently disabled

I am programming a web service . When I publish the web service on Server1 (Windows 2012 With IIS 8),it works fine,but if I publish on Server2 (Windows 2012 With IIS 8), it gives following error
Metadata publishing for this service is currently disabled.
I have tested on Server3 (Windows 2019 With IIS 10), I get the above error
it seems that it might be the IIS setting , because in server1 it is working fine.
This is the web.Config of the service
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="ECartContext" connectionString="metadata=res://*/ECartModel.csdl|res://*/ECartModel.ssdl|res://*/ECartModel.msl;provider=System.Data.SqlClient;provider connection string="data source=databaseServer;initial catalog=ECart;integrated security=True;Connection Timeout=30;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ManagementServiceBehaviour">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior>
<dataContractSerializer maxItemsInObjectGraph="2147483646" />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<bindings>
<basicHttpBinding>
<binding maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" >
<readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483648" />
</requestFiltering>
</security>
</system.webServer>
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "c:\log\Traces.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
</configuration>
with this config the service works on Server1 only, not Server2 and Server3
how can I check the problem?
You need to add the endpoint in the servicemodel:
<services>
<service name="WcfService2.Service1" behaviorConfiguration="ManagementServiceBehaviour">
<endpoint address="" contract="WcfService2.IService1" binding="basicHttpBinding"></endpoint>
</service>
</services>
I suspect that you have an endpoint in server1 but there is no endpoint in serve2 and server3.

WCF Service hosting in IIS and accessing it using Static IP

I am hosting a WCF service in IIS , it works fine on single system, but when I am trying to access it using remote machine(my system has static ip), it ask me username and password,
when I provide that using computer credentials , it doesn't accept it
Picture 1 shows that figure,
<?xml version="1.0"?>
<bindings>
<basicHttpBinding>
<binding name="Service1Soap">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" proxyCredentialType="None"
realm=""/>
<message clientCredentialType="UserName" algorithmSuite="Default"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="WCF_Static.WCF_Service" behaviorConfiguration="maxBehaviour">
<endpoint address="staticip" binding="basicHttpBinding" contract="WCF_Static.IWCF_Service" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost/8080"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="maxBehaviour">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
On Client side proxy I am using
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IWCF_Service" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://123.123.123.123/Alias/Service.svc/staticip"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IWCF_Service"
contract="ServiceReference1.IWCF_Service" name="BasicHttpBinding_IWCF_Service" />
</client>
</system.serviceModel>
</configuration>
Refereed links here
Thanks,
Found ! ! :)
deploy service as http://localhost/abc/Service1.svc?wsdl or (http://127.0.0.1/abc/Service1.svc?wsdl) in IIS, on client side add service reference as http://localhost/abc/Service1.svc?wsdl or http://127.0.0.1/abc/Service1.svc?wsdl ,
but in appconfig on client side
change the localhost or 127.0.0.1 to your ip address where actual WCF service is running.
in endpoint like this
endpoint address="http://123.123.123.123/max/Service.svc/static"

Poor Peformance with BIG IP F5 WCF NetTCpBinding

I am facing issue of poor performance when used WCF having NetTcpbinding with Load Balancer
We have win form application which consumes WCF (net.tcp protocol). In production we have web Farm having 3 servers with load balancer (F5). WCF hosted in IIS. We are testing with only 1 user
Now when we point WCF to specific server (using either server name or IP); application really perform well. However when we give the DNS name (so that request is pass through load balancer) there is a significant drop in performance. Network team is saying from there side everything is properly working. Please help
Following is the configuration that i have tin WCF web.config file.
<system.serviceModel>
<diagnostics performanceCounters="All" />
<services>
<service behaviorConfiguration="GetProxyEnabled" name="companyname.InvOps.ServiceLayer.PAServiceServer">
<host>
<baseAddresses>
<add baseAddress="net.tcp://USHOUIOWEB012VT/PAService"/>
<!--<add baseAddress="net.tcp://xxx.uat.companyname.net/PAService/"/>-->
</baseAddresses>
</host>
<endpoint address="netTcpAddress" behaviorConfiguration="NetTcpEndPointBehaviour" binding="netTcpBinding" bindingConfiguration="NetTcpBinding" contract="companyname.InvOps.ServiceLayer.IPAService" />
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="GetProxyEnabled">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceThrottling maxConcurrentCalls="200" maxConcurrentInstances="400" maxConcurrentSessions="200"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="NetTcpEndPointBehaviour">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding"
closeTimeout="05:45:00"
openTimeout="05:45:00"
receiveTimeout="05:45:00"
sendTimeout="05:45:00"
transactionFlow="false"
transferMode="Buffered"
transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard"
listenBacklog="10"
maxBufferPoolSize="2147483647"
maxBufferSize="2147483647"
maxConnections="10"
maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="32"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<reliableSession ordered="true"
inactivityTimeout="05:45:00"
enabled="false" />
<security mode="Transport">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign"/>
</security>
</binding>
</netTcpBinding>
</bindings>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
Really appretiate any feedback or suggesttion. Also what is the recommended settings on F5 when used WCF with NetTcpBinding.
I got it working now. It was Load Balance configuration issue. We have changed the Virtual Server type from Standard to Performance (Layer 7). The performance is not improved to acceptable range.

Visual Studio "Add Service Reference" - not gets all service settings

my purpose is to ensure that - when someone clicks on "Add Service Reference" in his own Visual Studio, and he adds references to my WCF service - he receives not the default settings, but the settings of the service.
In particular, there is a property of the "binding" class that interests me: useDefaultWebProxy, I need it setted to "false".
I tried this, but with no results:
In the Web.config file of the service:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="NewBinding0" ... useDefaultWebProxy="false">
<readerQuotas ... />
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="NewBehavior0" name="pippo.pluto">
<endpoint address="" behaviorConfiguration="" binding="basicHttpBinding"
bindingConfiguration="NewBinding0" name="pluto" contract="pippo.ipluto" />
<host>
<timeouts ... />
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="NewBehavior0">
<serviceMetadata ... />
<serviceDebug ... />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Nothing to do: in the client's Web.config I always get...
<basicHttpBinding>
<binding name="pluto" ... useDefaultWebProxy="true">
<readerQuotas ... />
<security ...>
<transport ... />
<message ... />
</security>
</binding>
</basicHttpBinding>
It seems that the bindingConfiguration of the service is completely ignored, not only useDefaultWebProxy but also other properties - for example maxBufferSize - maintain the default values (65536)
How can I do?
Pileggi

how to configure HTTPS and HTTP binding for Ajax Enabled WCF web service

I encountered an errror during the accessing of my web service in https site.
i think this is a configuration error because its looking for an https binding.
here is the web.config of the web service:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
<services>
<service name="WebService.ListViewWebService" behaviorConfiguration="WebService.ListViewWebServiceBehavior">
<endpoint address=""
behaviorConfiguration="WebService.ListViewWebServiceAjaxBehavior"
binding="webHttpBinding"
contract="WebService.IListViewWebService"/>
<endpoint address="https://win-d741qhlbivf:13241/services/DPT/_vti_bin/DPT.WebService/ListViewWebService.svc"
behaviorConfiguration="WebService.ListViewWebServiceAjaxBehavior1"
binding="webHttpsBinding"
contract="WebService.IListViewWebService2"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="webHttpBinding">
<security mode="None" />
</binding>
<binding name="webHttpsBinding">
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="WebService.ListViewWebServiceAjaxBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="WebService.ListViewWebServiceBehavior">
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
thanks for the help in advance.
Also, I am not sure if this has something to do with the issue but the web application hosted in a cloud environment...do i need a special configuration for that?...
thanks again..
One of my tutorials will help you:
http://netpl.blogspot.com/2010/05/how-to-programmatically-configure-ssl.html
The tutorial starts with the declarative configuration and then shows how to create binding/endpoints programatically.
This config will respond to requests in HTTP and HTTPS , note that the ports are different and have to match what the host is expecting (in this case it happens to be iis)
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
<customErrors mode="Off"/>
</system.web>
<system.serviceModel>
<serviceHostingEnvironment minFreeMemoryPercentageToActivateService="0" />
<services>
<service name="KPIGetter_Library.KPIGetter">
<endpoint address=""
behaviorConfiguration="restfulBehaviour"
binding="webHttpBinding"
bindingConfiguration="webHttpBindingWithJsonP"
contract="KPIGetter_Library.IKpiGetter" />
<endpoint address=""
behaviorConfiguration="restfulBehaviour"
binding="webHttpBinding"
bindingConfiguration="webHttpsBindingWithJsonP"
contract="KPIGetter_Library.IKpiGetter" />
<host>
<baseAddresses>
<add baseAddress="http://hodbd05:8000/kpigetter" />
<add baseAddress="https://hodbd05:8001/kpigetter" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="restfulBehaviour">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="webHttpBinding" scheme="http" />
</protocolMapping>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true">
<security mode="None" />
</binding>
<binding name="webHttpsBindingWithJsonP" crossDomainScriptAccessEnabled="true">
<security mode="Transport" />
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
An important issue is that you should use webHttpBinding and not the basicHttpBinding for ajax-enabled WCF services.
A simple working example is found here: Scott's blog on asp.net

Resources