WCF Hosted as Service - windows

I have a VB.NET WCF service hosted as a Window Service. I was able to create an install package, install the service to my machine, and start the service manually from Services in Administrative Tools.
Now when I try to reference the service in my test console application (Address: http://localhost:8080/), I get the following error:
There was an error downloading 'http://localhost:8080'.`
Unable to connect to the remote
server No connection could be made
because the target machine actively
refused it 127.0.0.1:8080`
Metadata contains a reference that
cannot be resolved:
'http://localhost:8080/'. Could not
connect to http://localhost:8080/. TCP
error code 10061: No connection could
be made because the target machine
actively refused it 127.0.0.1:8080.
Unable to connect to the remote server
No connection could be made because
the target machine actively refused it
127.0.0.1:8080 If the service is defined in the current solution, try
building the solution and adding the
service reference again.
Not sure what I can do about this. Any ideas???
Thanks,
Jason.
Here's the code from app.config inside my service:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<sources>
<!-- This section defines the logging configuration for My.Application.Log -->
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLog"/>
<!-- Uncomment the below section to write to the Application Event Log -->
<!--<add name="EventLog"/>-->
</listeners>
</source>
</sources>
<switches>
<add name="DefaultSwitch" value="Information" />
</switches>
<sharedListeners>
<add name="FileLog"
type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
initializeData="FileLogWriter"/>
</sharedListeners>
</system.diagnostics>
<system.serviceModel>
<services>
<service name="ExStreamWCF.Service1"
behaviorConfiguration="ExStreamWCF.Service1Behavior">
<!-- Service Endpoints -->
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8080/Design_Time_Addresses/JasonsService/Service/" />
</baseAddresses>
</host>
<endpoint address="" binding="wsHttpBinding" contract="ExStreamWCF.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ExStreamWCF.Service1Behavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
If anyone needs more from me please let me know!

Not sure if it's really an issue - but on a production server, I would never use localhost as my base address.
So can you try to change:
<service name="ExStreamWCF.Service1"
behaviorConfiguration="ExStreamWCF.Service1Behavior">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8080/Design_Time_Addresses/JasonsService/Service/" />
</baseAddresses>
</host>
to
<service name="ExStreamWCF.Service1"
behaviorConfiguration="ExStreamWCF.Service1Behavior">
<host>
<baseAddresses>
<add baseAddress = "http://YourServerName:8080/Design_Time_Addresses/JasonsService/Service/" />
</baseAddresses>
</host>
Does that make any difference when calling into the service??

Related

WCF Test Service cannot add service

I'm using Visual Studio for a school project and I'm to create a simple WCF Service Application web service that I need to test using WCF Test Client.
I developed the service, but then when I run the debugger, it opens a web browser, I copy the link to the IService1.svc file, and try to add that to the test client, and it fails complaining it cannot get meta data.
I tried this on a fresh solution with a new project, and same thing.
My Web.config file:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.8.1" />
<httpRuntime targetFramework="4.8.1"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
Am I missing any steps in testing the web services?
Depending on your wcf configuration file, you can see the parts without endpoints and service contracts. You may have missed the <service.model> section:
<services>
<service name="Namespace.Service1">
<endpoint address="" binding="basicHttpBinding" contract="Namespace.IService1" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>

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"

Getting HTTPS to Work with WCF and a Windows Service

I tried updating the App.config files for the client and service for the MS sample applications in WF_WCF_Samples\WCF\Basic\Services\Hosting\WindowsService\CS\WindowsService.sln so that secure bindings were used but when the client makes the call to the service method an exception is thrown
"An error occurred while making the HTTP request to https:// .... /servicemodelsamples/service. This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server."
Inner exception "The underlying connection was closed: An unexpected error occurred on a send"
As far as I can see both the server and client configs match and use Transport security mode and the mex endpoint now uses mexHttpsBinding rather than mexHttpBinding with the service behaviour appropriately enabled.
Can someone tell me what is missing or incorrect as I have tried numerous tweaks with no success?
Thanks
The server and client configs are
<?xml version="1.0"?>
<!--Copyright (c) Microsoft Corporation. All Rights Reserved.-->
<configuration>
<system.serviceModel>
<services>
<service name="Microsoft.Samples.WindowsService.WcfCalculatorService">
<host>
<baseAddresses>
<add baseAddress="https://localhost:8000/ServiceModelSamples/service"/>
</baseAddresses>
</host>
<!-- This endpoint is exposed at the base address provided by host: https://localhost:8000/ServiceModelSamples/service -->
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="https" contract="Microsoft.Samples.WindowsService.ICalculator"/>
<!-- The mex endpoint is exposed at https://localhost:8000/ServiceModelSamples/service/mex -->
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<basicHttpBinding>
<!-- Configure BasicHttp binding with Transport security mode and clientCredentialType as None -->
<binding name="https">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<!-- For debugging purposes set the includeExceptionDetailInFaults attribute to true -->
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
and
<?xml version="1.0"?>
<!--Copyright (c) Microsoft Corporation. All Rights Reserved.-->
<configuration>
<system.serviceModel>
<client>
<endpoint name="" address="https://localhost:8000/servicemodelsamples/service" binding="basicHttpBinding" bindingConfiguration="Binding1" contract="Microsoft.Samples.WindowsService.ICalculator"/>
</client>
<bindings>
<basicHttpBinding>
<!-- Configure BasicHttp binding with Transport security mode and clientCredentialType as None -->
<binding name="Binding1">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
mex cant be https
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
change to
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

Hosting the same WCF Service in IIS and in Windows Service

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>

Resources