I have two Services called TemplateService, TemplateReportService (both defined in one WCF Service Library) to be exposed to the client application.
And, I am trying to host these services under Windows Service.
Can anyone please guide me if App.config in Windows Service will be same as the one in WCF Library?
Here is my app.config in WCF Library:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
<service behaviorConfiguration="ReportingComponentLibrary.TemplateServiceBehavior"
name="ReportingComponentLibrary.TemplateService">
<endpoint address="" binding="wsHttpBinding" contract="ReportingComponentLibrary.ITemplateService" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" ></endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/ReportingComponentLibrary/TemplateService/" />
</baseAddresses>
</host>
</service>
<service behaviorConfiguration="ReportingComponentLibrary.TemplateServiceBehavior"
name="ReportingComponentLibrary.TemplateReportService">
<endpoint address="" binding="wsHttpBinding" contract="ReportingComponentLibrary.ITemplateReportService" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/ReportingComponentLibrary/TemplateReportService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ReportingComponentLibrary.TemplateServiceBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
So, the App.config in my Windows Service(Where I am hosting above two services)
will be same as above or there are only some particular sections that I need to move.
Please guide.
Thank you!
First, remove the as we talked about in your other question. Second libraries don't have their own .config files and there is no (built in) way to import certain configuration sections in .NET. So you must consolidate the configuration settings for each library into the single app.config of the Windows service.
Related
I have developed a WCF application in .net framework 3.5. The application is working fine but when I deploy it in iis it is giving blank when I have tried to access the webservice using the url
http://mysite:8086/VpoService.svc
my configuration file is like this.
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="VpoService.VpoServiceTypeBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="VpoService.VpoServiceTypeBehavior"
name="VpoService.VpoServiceType">
<endpoint address="" binding="wsHttpBinding" contract="VpoService.IVpoService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<!--<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />-->
</service>
</services>
</system.serviceModel>
Try modifying your <endpoint>
<host>
<baseAddresses>
<add baseAddress="http://MachineIP/VpoService.svc" />
</baseAddresses>
</host>
It worked for me
i am new in wcf.i have simple wcf service for like calculator for add,substract,muliply,division etc. i have two endpoint in my service config file. one is basicHttpBinding and another one is netTcpBinding. when i am hitting f5 then wcf test client appear and showing the error wcf failed to add a service. service metadata may not be accessible but if i off the netTcpBinding and mex for netTcpBinding and hit f5 then wcf test client can invoke the service. here is my config entry. so please have a look and tell me why i am getting error for netTcpBinding and how to fix it.
<?xml version="1.0"?>
<!--Copyright (c) Microsoft Corporation. All Rights Reserved.-->
<configuration>
<system.serviceModel>
<services>
<service name="MyTcpActivation.CalculatorService" behaviorConfiguration="CalculatorServiceBehavior">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="PortSharingBinding"
contract="MyTcpActivation.ICalculator"/>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
<endpoint address="" binding="basicHttpBinding" contract="MyTcpActivation.ICalculator" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="" portSharingEnabled="true">
<security mode="None"/>
</binding>
</netTcpBinding>
</bindings>
<!--For debugging purposes set the includeExceptionDetailInFaults attribute to true-->
<behaviors>
<serviceBehaviors>
<behavior name="CalculatorServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.web>
<compilation debug="true"/></system.web></configuration>
please guide me where to fix in config file as a result there should no issue whatever binding i use. thanks
I think ... if you have two "IMetadataExchange" endpoints, then you need to provide different addresses. For example:
<service name="MyTcpActivation.CalculatorService" behaviorConfiguration="CalculatorServiceBehavior">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="PortSharingBinding" contract="MyTcpActivation.ICalculator"/>
<endpoint address="mex1" binding="mexTcpBinding" contract="IMetadataExchange"/>
<endpoint address="" binding="basicHttpBinding" contract="MyTcpActivation.ICalculator" />
<endpoint address="mex2" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
I have a WCF Service which has it's configuration file as specified below:
<system.serviceModel>
<services>
<service name="WCFService.ServiceClass" behaviorConfiguration="metaDataSupport">
<host>
<baseAddresses>
<add baseAddress="net.pipe://localhost/WCFService"/>
<add baseAddress="net.tcp://localhost:8100/WCFService"/>
<add baseAddress="http://localhost:8101/WCFService"/>
</baseAddresses>
</host>
<endpoint address="tcpmex"
binding="mexTcpBinding"
contract="IMetadataExchange" />
<endpoint address="namedpipemex"
binding="mexNamedPipeBinding"
contract="IMetadataExchange" />
<endpoint address=""
binding="wsHttpBinding"
contract="WCFService.IServiceClass" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="metaDataSupport">
<serviceMetadata httpGetEnabled="false" httpGetUrl="" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
I have 3 types of binding here: NamedPipeBinding, TcpBinding and wsHttpBinding.
I can add a reference with metadata at the following location
net.tcp://localhost:8100/WCFService/tcpmex
net.pipe://localhost/WCFService/namedpipemex
I have disabled the httpGet for the service in behavior.
The service reference is added but with the following configuration at client:
<system.serviceModel>
<bindings>
<wsDualHttpBinding>
<binding name="WSHttpBinding_IServiceClass" />
</wsDualHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8101/WCFService" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IServiceClass" contract="TCP.IServiceClass"
name="WSHttpBinding_IServiceClass">
</endpoint>
</client>
</system.serviceModel>
But since I added a reference using TCP Binding endpoint,
I expected :
address=net.tcp://localhost:8100/WCFService
and binding="mexTcpBinding"
The Service is working but I would like to know, What's going on here.
What is the reason for this. Is it due to the baseAddress or some preference is given to wsHttpBinding?
Thoughts are appreciated.
Thanks.
The mex binding (short for Metadata EXchange) is not an endpoint which can be used to consume your service. Instead, it's used only used to expose information (or meta information) about all the "real" endpoints of your service - notice that your service class doesn't implement the IMetadataExchange contract which you defined in your TCP/Pipe endpoints.
In your case, your service has only one "real" endpoint - the one using wsHttpBinding, which implements the WCFService.IServiceClass interface. That's why there's only one endpoint in your client configuration.
Now, if you had another endpoint using a non-metadata binding (and not the IMetadataExchange contract), they would show up in the client config as well:
<system.serviceModel>
<services>
<service name="WCFService.ServiceClass" behaviorConfiguration="metaDataSupport">
<host>
<baseAddresses>
<add baseAddress="net.pipe://localhost/WCFService"/>
<add baseAddress="net.tcp://localhost:8100/WCFService"/>
<add baseAddress="http://localhost:8101/WCFService"/>
</baseAddresses>
</host>
<endpoint address="tcpmex"
binding="mexTcpBinding"
contract="IMetadataExchange" />
<endpoint address="namedpipemex"
binding="mexNamedPipeBinding"
contract="IMetadataExchange" />
<endpoint address=""
binding="netNamedPipeBinding"
contract="WCFService.IServiceClass" />
<endpoint address=""
binding="netTcpBinding"
contract="WCFService.IServiceClass" />
<endpoint address=""
binding="wsHttpBinding"
contract="WCFService.IServiceClass" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="metaDataSupport">
<serviceMetadata httpGetEnabled="false" httpGetUrl="" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
I created a WCF application, starting with basicHttpBinding. In app.config, I have the following endpoint configured:
<endpoint address="" binding="basicHttpBinding" contract="JMMEcommerceService.IJMMEcommerceService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
This builds fine. However, I want to change the protocol from HTTP to HTTPS. If I change the endpoint declaration to:
<endpoint address="" binding="basicHttpsBinding" contract="JMMEcommerceService.IJMMEcommerceService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
(note: the only change is basicHttpBinding -> basicHttpsBinding)
I get the following warning a build time:
WCF configuration validation warning: The 'binding' attribute is invalid - The value 'basicHttpsBinding' is invalid according to its datatype 'serviceBindingType'.
Why would I get this warning? Is there something else that I need to change?
Here is the full app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="JMMEcommerceService.JMMEcommerceService">
<endpoint address="" binding="basicHttpsBinding" contract="JMMEcommerceService.IJMMEcommerceService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="https://localhost:8733/Design_Time_Addresses/JMMEcommerceService/JMMEcommerceService/" />
</baseAddresses>
</host>
</service>
</services>
<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="True" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
The basicHttpsBinding does not appear to exist in .NET 4.0, only in 4.5. Which version of .NET are you targeting?
If you like to enable HTTPS for your service, but not for your Metadata, you have to provide another base address for your HTTP-based Metadata Exchange endpoint.
<baseAddresses>
<add baseAddress="https://localhost:8733/Design_Time_Addresses/JMMEcommerceService/JMMEcommerceService/" />
<add baseAddress="http://localhost:8734/Design_Time_Addresses/JMMEcommerceService/JMMEcommerceService/" />
</baseAddresses>
Please note, that you have to assign another port too (8734). Two protocols can not use the same port!
PS: Do not forget to assign the correct certificate to the port 8733
I have created a WCF service in which i have one service contract and multiple services classes implementing the same contract.
Could you please tell me what to edit in the app.config and how to host this service in console app.
I have one service contract and i implemented this contract in three *.cs files in wcf.
Thanks.
here is the App.config that i have written
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="ProductService.Service1">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8732/Design_Time_Addresses/ProductService/Service1/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address ="" binding="wsHttpBinding" contract="ProductService.IService1">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
<service name="ProductService.RegistrationService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:7777/Design_Time_Addresses/ProductService/RegistrationService/"/>
</baseAddresses>
</host>
<endpoint address="" binding="wsHttpBinding" contract="ProductService.IService1">
<identity>
<dns value ="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
<service name="ProductService.ProductService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8888/Design_Time_Addresses/ProductService/ProductService/"/>
</baseAddresses>
</host>
<endpoint address="" binding="wsHttpBinding" contract="ProductService.IService1">
<identity>
<dns value ="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
<service name="ProductService.CatogeryService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/Design_Time_Addresses/ProductService/CatogeryService/"/>
</baseAddresses>
</host>
<endpoint address="" binding="wsHttpBinding" contract="ProductService.IService1">
<identity>
<dns value ="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="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>
</system.serviceModel>
</configuration>
I imagine you have defined several service operations on the service contract? What you are trying to do is not possible, nor is it desirable.
Because a logical service is associated with exactly one service contract, you cannot add more than one service for the same contract.
You can add multiple service endpoints per service contract, but not on a per operation basis. You may want to do this to offer your service across two or more different transports, for example, HTTP and HTTPS.
You can consume all the operations from a single service (you have 4 services defined, so just get rid of the last three), but I don't think that is what you want to do.
To host each service operation on a separate service endpoint, you will needs to break up your service contract into multiple contracts.
This is more desirable as it reduces coupling between your endpoints and makes it much easier to understand what is going on.