I have a question concerning the app.config files in a c# solution. My solution contains 6 projects, among them are 4 Class Library projects, a WCF Application project and a Windows Forms project. The WCF project and Windows Forms project both contain an app.config file, however in the WCF project it is named "app.config" and the Windows Forms version is "App.config". I placed a reference for a connection string in the "App.config" version for one of the Class Library projects and I was wondering how the solution knew which config file to use. I have included both files below. If any could help me understand this that would be great. Thanks!!!
App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
</startup>
<connectionStrings>
<add name="medFactors" connectionString="Data Source=JDH8865-1\SQLEXPRESS;Initial Catalog=MedicalFactors;Integrated Security=True"/>
</connectionStrings>
<appSettings>
<!--<add key="RepositoryType" value="FactorsRepositoryService.WCFServiceRepository,FactorsRepositoryService, Version=1.0.0.0, Culture=neutral"/>
<add key="RepositoryType" value="FactorsRepositoryCSV.CSVRepository,FactorsRepositoryCSV, Version=1.0.0.0, Culture=neutral"/>-->
<add key="RepositoryType" value="FactorsRepositorySQL.SQLRepository,FactorsRepositorySQL, Version=1.0.0.0, Culture=neutral"/>
<add key="CSVFileName" value="tbl_Zip-Factors.csv"/>
</appSettings>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IPersonService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:53959/MedFactorsService.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IPersonService" contract="WCFMedFactorService.IMedFactorsService"
name="BasicHttpBinding_IPersonService" />
</client>
</system.serviceModel>
</configuration>
app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IMedFactorsService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:53959/MedFactorsService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMedFactorsService"
contract="WCFMedFactorService.IMedFactorsService" name="BasicHttpBinding_IMedFactorsService" />
</client>
</system.serviceModel>
</configuration>
OK, let me complete the answer.
The App.Config file of a project that is the starting project of a solution, is used as the config file for the solution.
Related
I know this topic has been discused multiple times already, but unfortunately non of the provided solutions workd for me.
I try to transfer large files (up to 1.5 GB) from a client console application to a WCF service.
But I always get an HTTP error The remote server returned an unexpected response: (413) Request Entity Too Large. while transmitting the file content.
All information I found in the internet where about adding maxContentLength and similar configuration to web.config file.
But I assume I entered them at a wrong part from the web.config or so.
Edit 26.02.2020 18:35 (updated due to hints and new tests)
Based on the tipps from above I added some entries to config files and did some more tests.
In the mean time I found out a few things:
The number in web.config define the size in bit not in bytes as I read on severall pages
The number must be a valid int32 - so the maximum value is 2147483647
2147483647 bit are around 256 MByte - so it's understandable, that my testfile with around 400MB caused a problem
Overall, if it's not possible to transfer the large files - at least 20-30 MB should be possible.
For larger files I will find an other solution then.
To do easier tests I just created a new empty WCF service and a console application to test it.
You can find the complete sourcecode on Google Drive.
I included a 22MB test image as well, which doesn't work to transfer.
Different to my first problem, I now get a 404 error instead of a 413.
So somehow the IIS returns a 404 when the request is not matchable to a service instead of the previous 413.
A pretty strange behaviour for me.
The web.config and the app.config looks still the same as before (beside there is no entity framework stuff in).
Server web.config
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="mybinding" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<security mode="None"/>
</binding>
</basicHttpBinding>
</bindings>
<protocolMapping>
<add binding="basicHttpBinding" scheme="http" bindingConfiguration="mybinding" />
</protocolMapping>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
Client app.config
<?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="mybinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:53042/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="mybinding" contract="ServiceReference1.IService1"
name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
</configuration>
As I'm not a pro regarding web.config configuration, I assume, I just added the configuration in a wrong section of the XML.
Can anybody provide me some help, how my web.config need to look like, that I can transfer larger files.
Thanks in advance
Regards Markus
The service now publishes the endpoint using ProtocolMapping section, I suggest you name the binding and apply the configuration to the properties below.
<bindings>
<basicHttpBinding>
<binding name="mybinding" ... >
...
</binding>
</basicHttpBinding>
</bindings>
<protocolMapping>
<add binding="basicHttpBinding" scheme="http" bindingConfiguration="mybinding"/>
</protocolMapping>
If it doesn’t work, we could publish the service by using the following style.
<system.serviceModel>
<services>
<service name="WcfService1.Service1">
<endpoint address="" binding="basicHttpBinding" contract="WcfService1.IService1" bindingConfiguration="mybinding"></endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
</service>
</services>
Feel free to let me know if the problem still exists.
I have a VisualStudio solution with WebForms (called EDWMS) & WCF projects (called EDWMS.SYNC) inside. WCF is added as Service Reference to WebForms project by using Discover function. When running it locally in "release" mode, the WCF gets called correctly from app & works fine (though I need to run VS as Administrator for it to work).
But when publishing the webforms project to IIS 8 both via Web Deploy Package & FTP Publish, WCF doesn't seem to get published.
I tried to create WCF as a separate Site in IIS, then setting WCF project as "Startup project" in VS & publishing it to new site slot, also adding it's port to the site bindings. In this case I can browse .svc file & see that it's set up You have created a service. To test this service, you will need.... But when I call it from WebForms app it still fails to respond with this error:
There was no endpoint listening at http://localhost:8733/Design_Time_Addresses/ED_WMS.SYNC/Sync/ that could accept the message. This is often caused by an incorrect address or SOAP action.
The remote server returned an error: (404) Not Found.
This is code from WebForms app which calls WCF:
var client = new SyncClient("BasicHttpBinding_ISync");
client.InnerChannel.OperationTimeout = new TimeSpan(2, 00, 0);
var message = string.Empty;
try
{
var syncResult = new SyncResult();
syncResult = client.GetInventory(1, 2, 3);
message += $"Sync Result<hr/>Added: {syncResult.ItemsAdded}<br/>Updated: {syncResult.ItemsUpdated}<br/>Duration: {syncResult.Duration}";
((ICommunicationObject)client).Close();
}
catch (System.Exception ex)
{
(client as ICommunicationObject)?.Abort();
message += $"Error<hr/>{ex?.Message ?? "null"}<hr/>{ex?.InnerException?.Message ?? "null"}";
}
inventoryItemsLbl.Text = message;
This is my WebForms Web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>...</connectionStrings>
<appSettings>...</appSettings>
<system.web>
<authentication mode="Forms">
<forms loginUrl="Login.aspx" timeout="2880" />
</authentication>
<compilation targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" executionTimeout="900" />
<pages>...</pages>
</system.web>
<system.webServer><modules>...</modules></system.webServer>
<runtime>...</runtime>
<system.codedom><compilers>...</compilers></system.codedom>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true">
</serviceHostingEnvironment>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ISync" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8733/Design_Time_Addresses/ED_WMS.SYNC/Sync/"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISync"
contract="ServiceReferenceWMS.ISync" name="BasicHttpBinding_ISync" />
</client>
</system.serviceModel>
</configuration>
This is my WCF App.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>...</configSections>
<entityFramework>...</entityFramework>
<runtime>...</runtime>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="MobilityBeanSoapBinding" closeTimeout="02:00:00" openTimeout="02:00:00"
receiveTimeout="02:00:00" sendTimeout="02:00:00" maxReceivedMessageSize="100000000"
maxBufferSize="100000000" maxBufferPoolSize="100000000">
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://warehouse:8080/wmwebservice_ejb/MobilityBean" binding="basicHttpBinding" bindingConfiguration="MobilityBeanSoapBinding" contract="EdWmsReference.MobilityBean" name="MobilityRemotePort" />
</client>
<services>
<service name="ED_WMS.SYNC.Sync" behaviorConfiguration="MyServiceTypeBehaviors">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Design_Time_Addresses/ED_WMS.SYNC/Sync/" />
</baseAddresses>
</host>
<endpoint name="basicHttpEndpoint" address="" binding="basicHttpBinding" contract="ED_WMS.SYNC.ISync" bindingConfiguration="MobilityBeanSoapBinding"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors" >
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
When you move from DEV -> Production( when the WCF app is now hosted in IIS), the design time URL changes, you would need to set the correct designTime URL in your webforms app now.
A few options are available, but they all point to changing the URI that is associated with the service
client.Endpoint.Address = new EndpointAddress(Server.IsLiveServer() ?
#"LiveUrl" : #"TestURl");
Where the TestURI is the designTime URL, and the LiveURL is the production URL. The IsLiveServer is just a boolean to check if you are in dev or production.
The other way you can go about it is to just to create a Realease vs a Debug webconfig, the release will have the URL of the deployed App, then set the client Endpoint using an appSetting or something similar
The third option would require using the IIS Administration DLL to query the hosted website and findout the URL of the WCF service and use that in your webforms.
Over the past few weeks I have developed a 64-bit WinForms application that needs to communicate with a 32-bit DLL (job specs require it).
After doing some reading around the internet and finding out that there is not going to be any fun way of doing this, I decided to go with hosting a WCF Service Application within my WinForms application for communicating to the 32-bit DLL... or so I thought I was doing.
During development (while running within Visual Studio) it has been working really well, but of course, now that I need to deploy, I am running into problems. I am having trouble getting a strong enough understanding of WCF Services to know if I am going about this in a terrible way or if I am just missing some minute detail.
I created the project as Admin. After development was finished I tried to run the WinForm executable (both debug and release), WindowsFormsApplication1.exe. The application started up, but after I tried to complete a task involving the use of the WCF service, an exception was thrown:
This has led me to believe that Visual Studio was doing the hosting of the service during development instead of the WinForm application, or my configs and/or directory structures are incorrect.
[UPDATED] WCF Service Web.config:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" maxRequestLength="2147483647"/>
</system.web>
<system.net>
<defaultProxy>
<proxy usesystemdefault="False"/>
</defaultProxy>
</system.net>
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true" >
<listeners>
<add name="xml"/>
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging">
<listeners>
<add name="xml"/>
</listeners>
</source>
<source name="myUserTraceSource"
switchValue="Information, ActivityTracing">
<listeners>
<add name="xml"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add name="xml"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="C:\logs\Traces.svclog" />
</sharedListeners>
</system.diagnostics>
<system.serviceModel>
<diagnostics wmiProviderEnabled="true">
<messageLogging
logEntireMessage="true"
logMalformedMessages="true"
logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="true"
maxMessagesToLog="3000"
/>
</diagnostics>
<behaviors>
<serviceBehaviors>
<behavior name="metadadiscovery>
<!-- 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>
<services>
<service name="ServiceReference1.Service1" behaviorConfiguration="metadadiscovery">
<endpoint address="" binding="basicHttpBinding" contract="ServiceReference1.IService1"></endpoint>
</service>
</services>
<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="false"/>
</system.webServer>
</configuration>
WinForm App.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService2" />
<binding name="BasicHttpBinding_IService3" />
<binding name="BasicHttpBinding_IService1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:45053/Service2.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService2" contract="ServiceReference2.IService2"
name="BasicHttpBinding_IService2" />
<endpoint address="http://localhost:46351/Service3.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService3" contract="ServiceReference3.IService3"
name="BasicHttpBinding_IService3" />
<endpoint address="http://localhost:44848/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
<appSettings>
<add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings>
<system.web>
<membership defaultProvider="ClientAuthenticationMembershipProvider">
<providers>
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
</providers>
</membership>
<roleManager defaultProvider="ClientRoleProvider" enabled="true">
<providers>
<add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
</providers>
</roleManager>
</system.web>
</configuration>
Directory Where EXE resides:
The directory containing the WCF Service resides within the directory WcfService1 from the image above.
I have mostly been using the following method of instantiating the service:
ServiceReference1.Service1Client = new ServiceReference1.SErvice1Client();
Once I tried to switch to using a service host (below), but when I used that method, the service would timeout whenever it tried to communicate to the DLL.
Uri address = new Uri("http://localhost:44848/Service1.svc");
ServiceHost host = new ServiceHost(typeof(ServiceReference1.Service1Client), address);
host.Open();
And then I closed the host later. At this point, I am willing to try anything to get this working.
[EDIT] Below is the code of my WindowsFormsApplication1.exe.config file. All three contracts are giving the warning that they're "invalid according to its datatype 'clientContractType'". I think this could be the source of my problems, but I do not know why it is showing this warning:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService2" />
<binding name="BasicHttpBinding_IService3" />
<binding name="BasicHttpBinding_IService1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:45053/Service2.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService2" contract="ServiceReference2.IService2" name="BasicHttpBinding_IService2" />
<endpoint address="http://localhost:46351/Service3.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService3" contract="ServiceReference3.IService3" name="BasicHttpBinding_IService3" />
<endpoint address="http://localhost:44848/Service1.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
</configuration>
Thank you for any help and guidance you can provide.
There is no endpoint configured for your service.
<behaviors>
<serviceBehaviors>
<behavior name="metadadiscovery">
<!-- 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>
<service name="ServiceReference2.Yourimplementingservice" behaviorConfiguration="metadadiscovery">
<endpoint address="" binding="basicHttpBinding" contract="ServiceReference2.IService2">
</endpoint>
Above I have configured for Service2 ,similarly you have to configure for Service1 and Service3.
After sufficient struggling I decided to get rid of the WCF service that visual studio generates for you when you create it as a new project. I instead followed this tutorial verbatim:
Hosting Service In App
Doing this came with huge advantages:
No configuration file was necessary
Running it this way must've gotten rid of a large amount of overhead because the communication to the DLL (what I am using the service for) used to take several seconds to do large amounts of calls to the DLL, but now is able to handle 10k+ calls in the blink of an eye.
No service reference is necessary. I just needed the file for my main function, the file containing the service function implementations and the file containing the interface for the implementation.
So far, this has been the easiest and most robust way I have found for using a 32 bit DLL in a 64 bit application. Let me know if I can give any guidance for anyone else who may be struggling with this problem. I know this is not a fun thing to deal with if you've never done anything like it before.
For some days now, i'm trying to access my WCF Service from another computer on my LAN and just can't access it.
Locally it works fine though.
Majority of the similar questions i could find are using IIS to host the service.
I tried to shut down the firewall but i couldn't get any effect.
Here are the config files, please ask if you need more :
Client's App.config :
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
<system.serviceModel>
<client>
<endpoint name="default"
address="http://myhostIP:3100/"
binding="basicHttpBinding"
contract="ServiceInterface.IService"/>
</client>
</system.serviceModel>
</configuration>
Here is the Host App.config :
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
<system.serviceModel>
<services>
<service name="ServiceTest.Service">
<endpoint address="http://0.0.0.0:3100"
contract="ServiceInterface.IService"
binding="basicHttpBinding"/>
</service>
</services>
</system.serviceModel>
</configuration>
If you guys got any ideas...
I couldn't find any informations
EDIT :
I'm using a console application to host the service
Telnet connection from local and remote hosts are working
EDIT 2 :
I just seen that i made a mistake copying the App.config file. The binding type should be wsDualHttpBinding instead of basicHttpBinding
I also could get an error message :
First one is that the "Caller couldn't identicate itself to the WCF service"
I tried then to set the security to none (for troubleshooting purposes) and i only got a timeout exception
EDIT 3 :
In a console app :
static void Main(string[] args)
{
ServiceHost host = new ServiceHost(typeof(ServiceTest.Service));
host.Open();
Console.WriteLine("Server Started");
Console.ReadLine();
}
Edit 4:
The complete solution is available here https://github.com/sidewinder94/smallChatSolution
Here is the solution for your issue.
Client's app config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
<system.serviceModel>
<client>
<endpoint name="default"
contract="ChatDllContracts.IService"
binding="netTcpBinding"
address="net.tcp://myHostIp:3100/"
bindingConfiguration="mynet"/>
</client>
<bindings>
<netTcpBinding>
<binding name="mynet" sendTimeout="00:00:05" portSharingEnabled="true">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>
</configuration>
ChatServer's app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
<system.serviceModel>
<services>
<service name="ChatDll.Service">
<endpoint contract="ChatDllContracts.IService"
binding="netTcpBinding"
address="net.tcp://localhost:3100"
bindingConfiguration="mynet"/>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="mynet" sendTimeout="00:00:05" portSharingEnabled="true">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>
</configuration>
Please keep in mind that you need to enable the Net.Tcp Port Sharing Service (on the server & client side) in order to get it working.
I have a wcf config in client side. I need use a key in AppSettings by ServerIP Name for other sections in App.Config instead of localhost, Because count of my endpoints is many and my server ip is variable. How can I it?
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="ServerIP" value="localhost"/>
</appSettings>
<system.serviceModel>
<bindings>
...
</bindings>
<client>
<endpoint address="net.tcp://localhost:9000/WcfServices/Person/PersonService"
binding="netTcpBinding" bindingConfiguration="RCISPNetTcpBindingWpf"
contract="Common.ServiceContract.IPersonService" name="BasicHttpBinding_IPersonService">
<identity>
<dns value="localhost" /> <!--How use ServerIP in appSettings instead of localhost-->
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
Normally you can not do that, but you might be able to use web.config transformations if you are using VisualStudio 2010. I think you have to use web deploy, or run an MSBuild task yourself to run the transforms.
you could not use appsettings in app.config itself.
you have two possibilities:
-use appsettings by code like making your our custom section
http://haacked.com/archive/2007/03/12/custom-configuration-sections-in-3-easy-steps.aspx
-use a nant build or msbuild with a placeholder
How to use MSbuild property in TransformXml task?