The type or namespace name 'Service Host' could not be found in .NET5 - wcf

I recently converted my .NET framework WCF application to .NET5.
I am getting the Service Host could not be found error.
'File' does not contain a definition for 'GetAccessControl'
I have installed these nuget packages but no luck.
System.ServiceModel.Primitives
System.ServiceModel.Http
System.ServiceModel.Security
System.ServiceModel.Duplex
System.ServiceModel.NetTcp
System.Private.ServiceModel
I am not sure what is the replacement of Service Host and Access Control in .NET5.
Could someone please help me?
serviceHost = new ServiceHost(typeof(Api));
FileSecurity fileSecurity = File.GetAccessControl(outputFile);

The class libraries of System.ServiceModel.* (also commonly called WCF client) is available as separate nuget packages.
The most compatible version for .NET 5.0 is System.ServiceModel.* version 4.8.1 so you should use this version.
For ServiceHost, .NET Core does not provide this. Because this means that the code will act as WCF as server, not WCF client. Microsoft itself has stated that it won't support WCF as server based on this blog article: https://devblogs.microsoft.com/dotnet/supporting-the-community-with-wf-and-wcf-oss-projects/
Fortunately, there's an ongoing effort from OSS to provide WCF server support for .NET Core, and it's called CoreWCF:
https://github.com/CoreWCF/CoreWCF
Currently (as far as I know) it supports BasicHttpBinding and TCP binding.

Related

WCF and Java web service connection issue

I've started a team project were each team needs to create a web service which will need to expose various methods. Our team has created a WCF web service and have had no problems with the other teams consuming our services except for one team, which I'll refer to as Team B. Team B created their web service using an older version of Java (no clue what version) which doesn't support metadata exchange.
Since we are all new to WCF, and web services in general, does anyone know of a way to solve this problem?
Thanks in advance
There are 2 types of metadata exchange - one is WSDL, and the other is MEX. WCF supports both. As long as you can open the web service url in a browser and see a WSDL file I'm in doubt if there is such an older java version that does not support it. MEX is a different thing but as long as you work with WSDL not interesting. You need to check with the Java team how their version supports generating clients from WSDLS (typcally there are command line tools like wsdl2java or IDE plugins) and then give them the WSDL url. It may be that there is a specific construct in the WSDL which they do not support in which case ask them for the error message.

.Net 4.5 WCF Error 404.3 on IIS 7.5

I deployed a MVC4 web application including a wcf service.
when i try to browse to the .svc file i receive Error 404.3 (Error Code 0x80070032).
I tried all the relevant answers i read:
1. adding a .svc mime
2. checking that the server's ISAPI filter include ASP.Net 4 bothe 32bit and 64bit.
3. checking that Server Managers Features include WCF Activation.
I already have a MVC3 web application with WCF service running on the same server.
Can you please point me to what can cause this problem?
I noticed that on IIS Manager in Handler Mapping there is a difference between the two domains running the applications. the working one is almost empty (include only StaticFile) while the new one has a long list of handlers enabled (I don't know if it is relevant or not).
Thank You!
I had to tick "HTTP Activation" in "Add Role Services" within Windows Server 2012.
Run command aspnet_regiis -iru in command prompt as an admin and try again.
Make sure the two WCF services are not running on the same port -- that is, you are not connecting to the MVC3 WCF service. See How to consume multiple WCF services from one client for how to do this.

Unable to host WCF REST Service 40(CS) on IIS 7

I have created WCF REST service in vs2010(4.0) with WCF REST Service Template 40(CS). It works fine on localhost and local IIS (7.5), without giving me any errors. But while I am trying to deploy it on server, it gives me 500 Internal server error. I have deployed same way I did on locl IIS. It is not giving me more details about the error. When I checked the server log, it says service.svc - file does not exist. While I have not created .svc file, I did directly with given template.
Can any one please help me to find the solution to this...
Thanks in advance...
I am using template, so there is no .svc file. In this we can directly access the uri without .svc with the filename.
Chrome is just displaying me 500 Internal server error. It is not displaying any related information about error.
-
Satyen Pandya
finally I found the thing that causes error in my service. I have used MySQL database and for that reference to MySql.Data.dll file of older version, and when I upgraded that dll with newer version, my entire project was not responding. It was replaced my newer version and when I tested with older version, service is running fine.
And for hosting it on WCF, Normal procedure of hosting the site on IIS worked for me after solving above problem... And I better opt for going with .net 3.5 WCF Rest Service with .svc extension available.
Thanks all for reviewing my problem..
Take a look at similar post...
# hosting .net 4.0 REST WCF service in IIS 6

Wshttpbinding translated to basic

I have a WCF service composed by two projects:
WCF service library
WCF Web application
The First project has a service call IMyService implemented by MyService. It is configured by using WS binding and if I press F5 on this project the WCFTestClient render the WS binding.
In the web app I have an .svc file with this markup with the same name
<%# ServiceHost Language="C#" Debug="true" Service="[Namespace].MyService" %>
If I press F5 on this project it renders a BasicHttpBinding. Same in the Client.
Why?
I have just checked that WCF Service Library project by default creates app.config with WSHttpBinding used for default service. When you run WCFTestClient it always uses this local config. If you want to use WCFTestClient to test additional services you must add their configuration to this config. This config is never used for anything else.
WCF Service application uses web.config. In WCF 4.0 it uses simplified configuration which adds endpoints based on some predefined conditions. By default it adds BasicHttpBinding endpoint to all services exposed over HTTP with common ServiceHostFactory.
How is your config file configure? If you configure the endpoint to use the wshttpbinding, this is the one that should be used.
Would you mind adding some code here (including the binding and endpoint details from the config file), so we could take a look?
Thanks,
Roberto Lopes.
I believe the original question was very poorly posed, to get a satisfactory answer you need to clearly state all the details.
First which version of Visual Studio are yo using? Since nothing is said, I'll assume it's the latest version VS2010 with SP1.
Let's say you have a visual studio solution that has two projects, one is a WCF Service Library, another is a WCF Application, both created using the default project template without any manual tweaking.
The WCF Service Library will have a app.config file with the following line:
in short, Visual Studio 2010 (SP1) uses wsHttpBinding for WCF Service Library projects by default.
The WCF Service Application project, however, will have a web.config file that contains no explicit endpoint definition, in which case, the default endpoint binding used is basicHttpBinding.
The OP said "When I pressed F5 on this project ....", this is a very misleading statement.
What does it mean to "press F5 on a project"? Do you mean you selected the project node in the solution tree, then pressed F5? if that's the case, what happens will always depend on which project is set as the start-up project in the solution (not on which project node is currently selected in Visual Studio UI).
If the WCF Service Application project is the start-up project, pressing F5 will NOT cause the WCF test client to run, instead, it will cause the folder of the project to be displayed in IE.
If the WCF Service Library project is the start-up project, the WCF test client will be run, and this is only because in the debug section of the project's properties window, the start options has the following by default:
/client:"WcfTestClient.exe"

How do I deploy a WCF service library to WAS?

I have created a WCF service library (not a WCF service application).
The project output is a dll.
How can I host this on IIS 7.5/WAS?
I believed that creating a service library was the way to go so that it could be used on a variety of hosts, whereas the service application is limited to IIS.
I'm getting lost in MS mumbo jumbo here, so I'd appreciate any help on getting this service deployed.
Thanks!
Edit
I got the service hosted by following these instructions:
http://msdn.microsoft.com/en-us/library/ms733109.aspx.
It seems like there has to be a better way to host service libraries. Deployment shouldn't require taking settings from app.config and moving them into web.config. Is it standard to wrap them in service applications? Is that even possible?
How are other people handling this?
Yes, creating separate library is good practice because hosting code is not coupled with your services. But you still have to write a host. In WAS, host is in a Web application. To host service in WAS you have to create .svc file and configuration for each service. That is the reason why you have to copy configuration from app.config to web.config. In .NET 4.0 this can be simplyfied with configuration based activation (no .svc is needed) end default endpoints.