Deploying a simple WCF Service to web server - wcf

Created a new Directory XYZ in IIS 7.0. Copied the web.config, Service.cs and Service.svc to the directory. Now on browsing http://www.mydomain.com/XYZ/Service.svc I am getting a '500 internal server error'.
Here is the web.cofig file.
<?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 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>
I am thinking there might be some problem with the config file, but the service runs pretty ok on local machine.

At first, you must use dll-file instead of code file. Compile code and put dll into the "bin" folder.
At second, you didn't add endpoints into web.cofnig:
<system.serviceModel>
<!-- ... -->
<services>
<service name="SiteService">
<endpoint address="" binding="basicHttpBinding"
contract="Name of the service interface with namespace, for exanple WebApplication1.IService1" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
And check svc file, a service name inside it should correspond to a service name inside a config file. If a service has a line <service name="SiteService">, svc file should be
<%# ServiceHost Language="C#" Debug="true" Service="SiteService" CodeBehind="Service.cs" %>

Related

WCF service metadata (wsdl) cannot be accessed: error 400

I have a problem with WCF metadata on a new installation ( IIS 10 on Windows Server 2016)
Situation
WCF service running fine (as it used to do on previous installation)
Navigation (via browser) of wsdl is NO more possible, or better
http://ServiceA/ServiceA.svc: yes (web page available) but link to xml not working (error 400 from IIS)
https://ServiceA/ServiceA.svc: not even the page
Moreover in the serviceMetadata it is stated to use https no http, that is in contrast with the behaviour just described.
Below an extract of web.config
<services>
<service behaviorConfiguration="ServiceBehavior" name="...">
<endpoint address="https://<fqdn>/ServiceA/ServiceA.svc"
binding="wsHttpBinding"
bindingConfiguration="wsHttpEndpointBinding"
name="WsHttpBinding"
contract="ServiceContracts.IServiceA">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<serviceMetadata httpsGetEnabled="true" httpGetEnabled="false" />
...
Could it be something linked to name resolution?
The PC name is AAAAAA, the FQDN is BBBBB.domain.ext
Thanks for any suggestion
L.
The WCF service deployed in IIS does not need to set the endpoint address in web.config.
Here is my demo:
<?xml version="1.0"?>
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<compilation debug="true">
</compilation>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows" />
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
</system.web>
<system.webServer>
<!--
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>
<system.serviceModel>
<services>
<service name="WcfService25.Service1" behaviorConfiguration="WcfService25.Service1Behavior">
<!-- Service Endpoints -->
<endpoint address="" binding="basicHttpBinding" contract="WcfService25.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>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfService25.Service1Behavior">
<!-- 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>
</system.serviceModel>
</configuration>
This is web.config. This project is a template project.
The base address of the WCF service in IIS is as follows:

System.IO.DirectoryNotFoundException In WCF Webservice

I am creating WCF web service. So i got an example in Github. Project Example
I am able to compile the project. But i am getting System.IO.DirectoryNotFoundException error.
My URL is: http://127.0.0.1:8080/v1/HelloService.svc/
My IDE: Visual Studio 2019 MAC
web.xml
<?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">
<serviceActivations>
<add relativeAddress="v1/HelloService.svc"
service="FilelessActivation.Services.HelloServiceImpl"
factory="System.ServiceModel.Activation.ServiceHostFactory" />
</serviceActivations>
</serviceHostingEnvironment>
<services>
<service name="FilelessActivation.Services.HelloServiceImpl">
<endpoint binding="basicHttpBinding"
bindingNamespace="http://oscarkuo.com/v1/hello"
contract="FilelessActivation.Services.IHelloService" />
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
The root cause is that we have to enable Windows feature to support SVC extension in IIS. Subsequently, we could have this service working.
Besides, please note, In the WCF project, No need SVC file doesn’t represent that the relative address in the ServiceActivations doesn’t contain SVC extension.
Result.
Related links.
https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/configuration-based-activation-in-iis-and-was
Feel free to let me know if the problem still exists.

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” />

How To Change The Binding of a WCF Service

I have a very simple (see any getting started sample online) wcf service library. And i can run it via the WCF Test Client exe on localhost. But when accessing it via another client tool, like soapUI, i get errors. I believe the errors are related to security configuration of the service.
How can i change the binding of a service, like is suggested in this post:
"Invalid or expired security context token" when running after a debugging restart
Is this in app.config or web.config. my project doesnt even have a web.config.
Here's my app.config:
<?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="NorthwindServices.ProductService">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8732/Design_Time_Addresses/NorthwindServices/ProductService/" />
</baseAddresses>
</host>
<endpoint address ="" binding="wsHttpBinding"
contract="NorthwindServices.IProducts">
<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>

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.