Confusion about default WCF project web.config layout - wcf

Below is the default layout for the web.config of a new WCF Service Application in VS2012.
What confuses me is that it doesn't seem to match any examples or tutorials online. There are no endpoints or bindings defined, yet it's possible to call the service.
I hit a problem when trying to increase the MaxReceivedMessageSize property - I googled it and didn't have a clue where to look in my web.config.
Can someone point me in the right direction of why it's so strangely laid out?
I expected it to look more like This SO question about setting MaxReceivedMessageSize or even any WCF tutorials like Michelle Bustamante's which is how I originally learned WCF.
<?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>
<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>

Starting with .NET 4.0, WCF introduced the concepts of default endpoints and bindings, allowing developers to create a service without having to define a bunch of stuff in the configuration file.
The posted config file is targeting 4.5, which is why you're seeing such a naked WCF config. If you need to increase your maxMessageSize, you'll need to explicitly define it in the config.
You can do this by either setting that binding definition as the default (by omitting the name attribute on the binding element), or creating an endpoint and explicitly assigning the binding configuration you defined via the bindingConfig attribute.
See A Developer's Introduction to Windows Communication Foundation 4.
You can also check a previous answer by me that has examples: https://stackoverflow.com/a/16099054/745969

Related

HTTP Error 500.19 while hosting Wcf Service

I am hosting Wcf application on my local machine(32 bit machine).I am getting below error.
Config Error This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".
Attaching the Config file details for the same.
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="WcfServiceDemo.ServiceCalculateCost" >
<endpoint address="" binding="wsHttpBinding" contract="WcfServiceDemo.IServiceCalculateCost"></endpoint>
</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>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
IIS 7 implements "Configuration Locking". This is to help with IIS administration.
Here, look at the error details and how to resolve the same: IIS 7 – This configuration section cannot be used at this path.
As per it, one of the resolution:
Open the applicationHost.config file, located here: %windir%\system32\inetsrv\config\applicationHost.config
Edit the "handlers" section.
Change this line:
<section name=”handlers” overrideModeDefault=”Deny” />
To:
<section name=”handlers” overrideModeDefault=”Allow” />

Seeting the default page of the svc-less WCF service

I made a 'Hello World' WCF service. The service doesn't have a svc file.
Therefore the web.config file determines its address and other settings.
However, I'm stuck with opening the specific page.
When I run the WCF service project, it always shows the error page (HTTP Error 403.14).
This is because the browser tries to go to localhost instead of localhost/HelloWorldService.svc.
Do you know how can I solve it?
I want to open the localhost/HelloWorldService.svc when I start running the WCF service in VS 2012.
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
<a href="http://go.microsoft.com/fwlink/?LinkId=169433">http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="false" targetFramework="4.5"/>
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<serviceHostingEnvironment >
<serviceActivations>
<add factory="System.ServiceModel.Activation.ServiceHostFactory"
relativeAddress="HelloWorldService.svc"
service="HelloWorldService.HelloWorldService"/>
</serviceActivations>
</serviceHostingEnvironment>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Go to Properties -> Web -> click Specific Page and enter /HelloWorldService.svc.

WCF application isn't running on IIS Express 7.5

I have a WCF service developed on .NET framework 4. My dev machine is running Windows 8, Visual Studio 2012 and I already published the service at IIS 8.
Now I need to publish the service on a Windows XP machine. I'm getting several errors on IIS 5.1, so I gave up to use this version and I'm trying to use IIS Express 7.5 with VS2010.
The service gets up with no problems, but I cant acess the WSDL cause it says that metadata is disabled.
What can I do to activate metadata on my WCF service?
Follows the web.config:
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="SAP.Middleware.Connector">
<sectionGroup name="ClientSettings">
<section name="DestinationConfiguration" type="SAP.Middleware.Connector.RfcDestinationConfiguration, sapnco"/>
</sectionGroup>
</sectionGroup>
</configSections>
<SAP.Middleware.Connector>
<ClientSettings>
<DestinationConfiguration>
<destinations>
<add NAME="XXX" USER="XXX" PASSWD="XXX" CLIENT="XXX" LANG="EN" ASHOST="mc0.sap.XXX.com" SYSNR="XXX" MAX_POOL_SIZE="XXX" IDLE_TIMEOUT="XXX"/>
<add NAME="QA" USER="XXX" PASSWD="XXX" CLIENT="XXX" LANG="EN" ASHOST="XXX" SYSNR="XXX" MAX_POOL_SIZE="XXX" IDLE_TIMEOUT="100"/>
</destinations>
</DestinationConfiguration>
</ClientSettings>
</SAP.Middleware.Connector>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<appSettings/>
<system.web>
<compilation targetFramework="4.0" debug="true"/>
<httpRuntime/>
</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="true"/>
</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>
You should check if in your config file that you enable mex.
e.g. (mex though http).
In your service behavior you should enable the following option
<serviceMetadata httpGetEnabled="true" />
In your endpoint list you should add the following
<endpoint address="/mex" binding="mexHttpBinding"
contract="IMetadataExchange" />
Save your config and rerun.
I found this topic wich instructs to use WEBMATRIX to host a WCF application in IIS Express. It worked perfectly for me.
Hope it can help somone else!
http://blogs.iis.net/vaidyg/archive/2010/07/29/serving-external-traffic-with-webmatrix-beta.aspx

All WCF services won't start

I don't know what the problem is, but I can't start any WCF services?
Even the standard method GetData won't work.
They all time out with an error:
Cannot obtain Metadata from localhost:9590/Service.svc
But I didn't change any of the code, and before now all my WCF services worked, but not now.
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false 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>
<serviceHostingEnvironment 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>
Do you add service metadata endpoint in the code or in service Web.config?
Missing metadata endpoint is the only thing i can think of.
Unless you have managed to redirect localhost to somewhere else..

Getting Error in Endpoint While Running A WCF REST Service

I'm developing a REST service using WebHttpBinding.
Everything is perfect in my service, but while running it gives Error Endpoint not Found.
The web.config File is like this:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<system.serviceModel>
<services>
<service name="Service">
<endpoint address="http://localhost:10492/Service.svc" binding="webHttpBinding" contract="IService" behaviorConfiguration="webby"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webby">
<webHttp helpEnabled="true"/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false 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>
<serviceHostingEnvironment 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>
In address I tried like this also:
<endpoint address="" binding="webHttpBinding" contract="IService" behaviorConfiguration="webby"/>
But it's still not working.
Here is a good link to get you started: http://weblogs.asp.net/kiyoshi/archive/2008/10/08/wcf-using-webhttpbinding-for-rest-services.aspx
On what address are you attempting to connect to your web service? (Have you tried navigating to the address in your web browser, and what URL did you type in?)
[EDIT]
Being that you are hosting in a web application, IIS (or whatever web server you are using) will expect that a service descriptor file exists for your service. You cannot just create a URI in the web.config, and host it in IIS without an associated 'service' file on the file-system (this is your Service1.svc file).
This is a nuance specific to hosting WCF services within Internet Information Services - it is easy to forget about this step, if you are reading tutorials designed for self-hosted scenarios.
Make sure that you have a file in your website called "Service1.svc" and it should contain something like this:
<%#ServiceHost Language="C#" Service="MyNamespace.Service1" Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>
Here is a tutorial on hosting REST services within IIS: http://saravananarumugam.wordpress.com/2011/03/04/simple-rest-implementation-with-webhttpbinding/
Another concern that jumps out at me, is that your endpoint address you have defined ("http://localhost:10492/Service.svc") does not conform to REST conventions. I wouldnt expect this would be your problem, but it is A problem.