System.IO.DirectoryNotFoundException In WCF Webservice - wcf

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.

Related

Another no endpoint listening

I read much about my problem but i can't find solution. When I go to controller with my service compiler returns:
There was no endpoint listening at {0} that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
InnerException:
Basic connection was closed: An unexpected error occurred when receiving
I try with mex and close my firewall, when I start app my service works correctly (I can visit localhost:52093/AccountService.svc) but when I go to controller to invoke service IIS stops working.
My web.config:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IAccountService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:52093/AccountService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAccountService"
contract="AccountService.IAccountService" name="BasicHttpBinding_IAccountService" />
</client>
</system.serviceModel>
Any ideas?
Thanks in advance
E:
My Service config
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.1" />
<httpRuntime targetFramework="4.5.1"/>
</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"/>
<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>
You seem to be missing the <service /> and <endpoint /> tags. Refer to this MSDN article on how to properly setup your Web.config for hosing your WCF service on IIS.

VB.NET solution to - " WCF service default project setup example does not work"

I know this has been asked before and I've went through 2 of the only answered questions here with a fine tooth comb, and many hours later trying every possible solution, I'm still not able to get the default WCF project to work on VS2012 (see error in title).
In a nutshell:
All I want to do is get the default WCF Application project to work in VisualStudio 2012 Pro.
What I've tried:
Changing the WEB.CONFIG end to add the following (this apparently, works for most, but not me)
<services>
<service behaviorConfiguration="metadataBehavior" name="Service1">
<endpoint
address=""
binding="customBinding" bindingConfiguration="jsonpBinding"
contract="Service1.IService1"/>
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
And the following:
<behaviors>
<serviceBehaviors>
<behavior name="metadataBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
The iService1.vb code (didn't change the default):
<ServiceContract()>
Public Interface IService1
<OperationContract()>
Function GetData(ByVal value As Integer) As String
<OperationContract()>
Function GetDataUsingDataContract(ByVal composite As CompositeType) As CompositeType
' TODO: Add your service operations here
End Interface
<DataContract()>
Public Class CompositeType
<DataMember()>
Public Property BoolValue() As Boolean
<DataMember()>
Public Property StringValue() As String
End Class
The markup for the Service1.svc:
<%# ServiceHost Language="VB" Debug="true" Service="WcfService1.Service1" CodeBehind="Service1.svc.vb" %>
Which, incidentally, has a long blue squiggly line indicating "Unrecognized configuration section services. (E:\projects\TestJquery\WcfService1\web.config line 35) " so I need something else here - another project reference?
Here's the complete web.config file (the only thing that changed was the recommended addition of the "services" section)
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" strict="false" explicit="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>
<services>
<service behaviorConfiguration="metadataBehavior" name="Service1">
<endpoint
address=""
binding="customBinding" bindingConfiguration="jsonpBinding"
contract="Service1.IService1"/>
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="metadataBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</configuration>
I figure, if I could just get the default WCF webservice project to work, I could better dissect and understand what is going on. If anyone has done this, please send a zip file of your working, functioning default VS2012 solution (or a link). I really want to get away from ASMX web services, the lexicon of WCF doesn't seem to make any sense.
web.config changes - still no workie, but no blue squigglies :)
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" strict="false" explicit="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>
<behavior name="metadataBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="metadataBehavior" name="WcfService1.Service1">
<endpoint
address=""
binding= "basicHttpBinding"
/>
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</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="true"/>
</system.webServer>
</configuration>
FINAL WEB.CONFIG settings necessary for default, out of the box, VS2012 WCF Web Service Application to work. I hope this helps all the newbies like me to at least have something to tweak with while learning WCF:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" strict="false" explicit="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>
<behavior name="metadataBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="metadataBehavior" name="WcfService1.Service1">
<endpoint
address=""
binding= "basicHttpBinding"
contract="WcfService1.IService1"
/>
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
<add binding="basicHttpBinding" scheme="http" />
</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>
Ok, so there's a number of things. As I said in the comments, the project should work without changes just fine out of the box.
The main issue in your posted code is that your web.config is not correct - you have the <services> and <behaviors> section outside of the <system.serviceModel> section, which is why you're getting the errors you're seeing. Additionally, the closing tags for your behaviors are in the wrong order.
What your config should look like is this:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="MyServiceBinding" />
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="metadataBehavior" name="WcfService1.Service1">
<endpoint address=""
binding="wsHttpBinding"
bindingConfiguration="MyServiceBinding"
contract="WcfService1.IService1"/>
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="metadataBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<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>
Note that I removed your custom binding and for purposes of illustration used wsHttpBinding and named the configuration MyServiceBinding. This will result in the service using that configuration section for binding information (and since I didn't set any values, it will be the defaults for that binding).
You could remove the entire service model section of the config and hit F5, and you will get a service that is exposed over a default basicHttpBinding endpoint.
Added
WCF is complex and has a steep learning curve. Binding configuration alone is a big subject, and probably one of the biggest causes of problems for developers in WCF. Remember the ABC's of WCF - Address, Binding and Contract. You must have all three to have successful running service.
With WCF 4.0 Microsoft implemented the concept of default endpoints, bindings, etc to make configuration easier, and they added additional stuff in 4.5. Take a look at A Developer's Introduction to Windows Communication Foundation 4 for a starter.

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

Deploying a simple WCF Service to web server

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" %>

WCF Polling Duplex Binding and Non-Silverlight Clients

I'm having a heck of a time figuring this out. I have a WCF service that I need to puch information to Silverlight client, but I need a console application to also be able to participate in this. Could anyone give me a hint on to what my Web.Config should look like to specify an additional binding that the console app could access? When I think I get things working the SL clients are unable to receive any messages...
Here is my current Web.Config:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<extensions>
<bindingExtensions>
<add name="pollingDuplex" type="System.ServiceModel.Configuration.PollingDuplexHttpBindingCollectionElement,System.ServiceModel.PollingDuplex, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</bindingExtensions>
</extensions>
<behaviors>
<serviceBehaviors>
<behavior name="">
<!-- 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>
</serviceBehaviors>
</behaviors>
<!-- Create the polling duplex binding. -->
<bindings>
<pollingDuplex>
<binding name="myPollingDuplex"
duplexMode="MultipleMessagesPerPoll">
</binding>
</pollingDuplex>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name ="EdiManager.Web.EdiPubSub">
<endpoint address=""
binding="pollingDuplex"
bindingConfiguration="myPollingDuplex"
contract="EdiManager.Web.EdiPubSub"
/>
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</service>
</services>
</system.serviceModel>
</configuration>
If you don't need full duplex just use wsHttpBinding instead of mex (or provide more info what would you like to achieve).
Do you want the console application to also participate in the polling duplex connection? Or will you want to use a different query-response binding?
Also, I notice that you're using AspNetCompatibility with polling duplex. If you're accessing session state you will experience some performance issues. I did a short blog post about it which references an MSDN blog post with testing information.
In short, the polling duplex is a long-timeout operation. The session state locks and no other requests can proceed until the poll times out and before it makes another connection that locks the session state provider again.
I was able to get it working by editing the config with the WCF Service editor and not doing it by hand. Clearly I was making some mistake editing the config manually. Here is the web.config that works:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<extensions>
<bindingExtensions>
<add name="pollingDuplex" type="System.ServiceModel.Configuration.PollingDuplexHttpBindingCollectionElement,System.ServiceModel.PollingDuplex, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</bindingExtensions>
</extensions>
<behaviors>
<serviceBehaviors>
<behavior name="">
<!-- 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>
<!-- Create the polling duplex binding. -->
<bindings>
<wsDualHttpBinding>
<binding name="myDualHttp" />
</wsDualHttpBinding>
<pollingDuplex>
<binding name="myPollingDuplex" duplexMode="MultipleMessagesPerPoll" />
</pollingDuplex>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="EdiManager.Web.EdiPubSub">
<endpoint address="Silverlight" binding="pollingDuplex" bindingConfiguration="myPollingDuplex"
name="Silverlight" contract="EdiManager.Web.EdiPubSub" />
<endpoint address="Console" binding="wsDualHttpBinding" bindingConfiguration="myDualHttp"
name="Console" contract="EdiManager.Web.EdiPubSub" />
</service>
</services>
</system.serviceModel>
</configuration>