WCF Web.Config - Duplicate Service Names Throwing Error - wcf

The following code is throwing the error
A child element named 'service' with same key already exists at the same configuration scope. Collection elements must be unique within the same configuration scope (e.g. the same application.config file). Duplicate key value: 'Marius.Marius_0_0_8'.
Now obviously there are two services named Marius.Marius_0_0_8. But when I try to change the name of one of them to something else I get a different error. I'm assuming that's because the name has to match the name of the namespace & class in the .svc.
I'm tired and have been staring at this for hours. What am I doing wrong? All I'm trying to really do is turn the Metadata on so I can hook up the WCF Test Client.
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.5.1" />
<httpRuntime targetFramework="4.5.1" />
<customErrors mode="Off" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="Marius.PublishTheMetaData" >
<!-- Add the following element to your service behavior configuration. -->
<serviceMetadata httpGetEnabled="true" policyVersion="Policy15" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="Marius.MariusAspNetAjaxBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service name="Marius.Marius_0_0_8">
<endpoint address="" behaviorConfiguration="Marius.MariusAspNetAjaxBehavior"
binding="webHttpBinding" contract="Marius.Marius_0_0_8" />
</service>
<service name ="Marius.Marius_0_0_8" behaviorConfiguration="Marius.PublishTheMetaData">
<endpoint name="mex"
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
</configuration>

You are trying to declare another service for the Mex endpoint. The correct way is to have only one service which exposes two endpoints: the real service endpoint and the wsdl endpoint.
<services>
<service name="Marius.Marius_0_0_8">
<endpoint address="" behaviorConfiguration="Marius.MariusAspNetAjaxBehavior"
binding="webHttpBinding" contract="Marius.Marius_0_0_8" />
<endpoint name="mex"
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
Example: https://msdn.microsoft.com/en-us/library/ms734786(v=vs.110).aspx

Related

Modify Program Using Sync Framework to use WCF

I'm trying to synchronize a client database with a central database. I successfully did that using the Synchronization framework as long as both the client and central database are on the same network. However, I need for this to work with the client being outside the network and the firewall. The firewall prevents communications on port 1433, so I started to explore WCF as an option so port 80 is used.
I tried this and put the WCF service under IIS 7:
http://code.msdn.microsoft.com/Database-SyncSQL-Server-e97d1208
but have gotten this error:
Failed: The caller was not authenticated by the service.
I searched high and low for a solution to this error but have found none. Does anyone know a tutorial on how to use the sync framework over WCF?
Here is the web.config file on the IIS server:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpRuntime maxRequestLength="65536" />
<customErrors mode="Off" />
</system.web>
<system.serviceModel>
<services>
<service behaviorConfiguration="WebSyncContract.SqlWebSyncService" name="WebSyncContract.SqlWebSyncService">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="largeMessageHttpBinding" contract="WebSyncContract.ISqlSyncContract">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://web-services.hexagroup.us/WebSyncContract.SqlWebSyncService.svc" />
</baseAddresses>
</host>
</service>
<service name="WebSyncContract.SqlSyncProviderProxy" behaviorConfiguration="WebSyncContract.SqlSyncProviderProxy" >
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
<service behaviorConfiguration="WebSyncContract.SyncService" name="WebSyncContract.SyncService">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="largeMessageHttpBinding" contract="WebSyncContract.ISyncContract">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<!--<add baseAddress="http://localhost:8080/"/>-->
<add baseAddress="http://web-services.hexagroup.us/WebSyncContract.SqlWebSyncService.svc" />
</baseAddresses>
</host>
</service>
</services>
<bindings>
<wsHttpBinding>
<!-- We are using Server cert only.-->
<binding name="largeMessageHttpBinding" maxReceivedMessageSize="2147483647" receiveTimeout="00:10:00" sendTimeout="00:10:00">
<readerQuotas maxArrayLength="2147483647" />
<!--<reliableSession enabled="true" />
<security mode="None" />-->
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="WebSyncContract.SqlWebSyncService">
<!-- 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="True" />
</behavior>
<behavior name="WebSyncContract.SqlSyncProviderProxy" >
<serviceMetadata httpGetEnabled="true" />
</behavior>
<behavior name="WebSyncContract.SyncService" >
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</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>

Hosting WCF service

I am following THIS link to create my wcf service and hosting through window service its is working fine but when i change my namespace from "Microsoft.ServiceModel.Samples" to "EE.ServiceProcess.ABC" and do changes accordingly in app.config my window service dont get start properly
my
App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="EE.ServiceProcess.ABC.CalculatorService"
behaviorConfiguration="CalculatorServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/EEServiceProcessABCservice/service"/>
</baseAddresses>
</host>
<!-- this endpoint is exposed at the base address provided by host: http://localhost:8000/EEServiceProcessABCservice/service -->
<endpoint address=""
binding="wsHttpBinding"
contract=" EE.ServiceProcess.ABC.ICalculator" />
<!-- the mex endpoint is explosed at http://localhost:8000/EEServiceProcessABCservice/service/mex -->
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="CalculatorServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Can any one please suggest where am i going wrong?

Hosting a WCF service using net tcp binding. Error: Service metadata may not be accessible

I have a Service Application which has the following web.config file:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<standardEndpoints>
</standardEndpoints>
<bindings>
</bindings>
<services>
<service behaviorConfiguration="metadatabehaviour" name="WCF_Service.HistorianService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration=""
contract="WCF_Service.IHistorianCollectorService" />
<endpoint address="net.tcp://localhost:8081/mex" binding="mexTcpBinding"
contract="IMetadataExchange" />
<endpoint address="net.tcp://localhost:8081" binding="netTcpBinding"
contract="WCF_Service.IHistorianCollectorService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="metadatabehaviour">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="false" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
And I am getting the following error: Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.
I can successfully run the service if I am just implementing the "basicHttpBinding" but as soon as I introduce a "netTcp" binding, I start getting this error. I have changed the 'mex' binding to 'mexTcpBinding' but still the error persists.
I have tried toggling the relevant properties. Any idea how I can correct this error?
It seems you actually disabled metadata exchange:
<serviceMetadata httpGetEnabled="false" />
It should be set to true!
I found out the solution. My port number for net.tcp had value '0'. I didnt know that was possible. Changing it to 808 did it.

WCF Default Endpoint Missing

I am deploying a WCF Service to IIS 7 and when I navigate to the service URL I get a page like this:
I do not get the typical landing page like this (copied from the web just to show example, data blurred to protect the innocent):
Can someone tell me what I am doing wrong? The service works as expected but there is nothing for a user of this service to view to know what the methods are or where to get the WSDL.
Here are my relevant files:
App.Config (in service project and copied to service site as Web.Config for IIS)
<system.web>
<compilation debug="true"/>
</system.web>
<system.serviceModel>
<services>
<service name="MyService.MyService" behaviorConfiguration="Web">
<clear />
<endpoint address=""
binding="wsHttpBinding"
name="ws"
behaviorConfiguration="Web"
contract="MyService.IMyService" />
<!--
<endpoint address=""
behaviorConfiguration="Web"
binding="webHttpBinding"
bindingConfiguration=""
name="web"
contract="MyService.IMyService" />
-->
<host>
<baseAddresses>
<add baseAddress="http://services.mydomain.com/MyService" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Web">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="Web">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
MyService.svc
<%# ServiceHost Service="MyService.MyService"
Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>
I also tried using 'webHttpBinding' instead of 'wsHttpBinding' and it didn't seem to make a difference.
ServiceHost Service="MyService.MyService" ... is this line correct?

mexTcpBinding in WCF - IMetadataExchange errors

I'm wanting to get a WCF-over-TCP service working. I was having some problems with modifying my own project, so I thought I'd start with the "base" WCF template included in VS2008.
Here is the initial WCF App.config and when I run the service the WCF Test Client can work with it fine:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
<service name="WcfTcpTest.Service1" behaviorConfiguration="WcfTcpTest.Service1Behavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8731/Design_Time_Addresses/WcfTcpTest/Service1/" />
</baseAddresses>
</host>
<endpoint address="" binding="wsHttpBinding" contract="WcfTcpTest.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfTcpTest.Service1Behavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
This works perfectly, no issues at all.
I figured changing it from HTTP to TCP would be trivial: change the bindings to their TCP equivalents and remove the httpGetEnabled serviceMetadata element:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
<service name="WcfTcpTest.Service1" behaviorConfiguration="WcfTcpTest.Service1Behavior">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:1337/Service1/" />
</baseAddresses>
</host>
<endpoint address="" binding="netTcpBinding" contract="WcfTcpTest.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfTcpTest.Service1Behavior">
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
But when I run this I get this error in the WCF Service Host:
System.InvalidOperationException: The contract name 'IMetadataExchange' could not be found in the list of contracts implemented by the service Service1. Add a ServiceMetadataBehavior to the configuration file or to the ServiceHost directly to enable support for this contract.
I get the feeling that you can't send metadata using TCP, but that's the case why is there a mexTcpBinding option?
Well, if you want to have metadata - TCP or HTTP - you still need to include the serviceMetadata behavior!
<behaviors>
<serviceBehaviors>
<behavior name="WcfTcpTest.Service1Behavior">
<serviceDebug includeExceptionDetailInFaults="True" />
<serviceMetadata />
</behavior>
</serviceBehaviors>
</behaviors>
Sure, you can't have a "HttpGetEnabled" on it - but the behavior itself must be present in order to enable exchange of metadata (and thus the IMetadataExchange contract).