Use of WebServiceHost2Factory - wcf

What is the use of "WebServiceHost2Factory".
I am creating Rest Wcf service.
I am using VS2010 so do I need to install WCF Rest Starter Kit??
When I added WebServiceHost2Factory to my service markup I am getting an error saying
"The CLR Type 'Microsoft.ServiceModel.Web.WebServiceHost2Factory' could not be loaded during service compilation".
What am I missing here.
here is my markUp for Service.
<%# ServiceHost Language="C#" Debug="true" Service="WCFRESTService1.Service1" CodeBehind="Service1.svc.cs" Factory = "Microsoft.ServiceModel.Web.WebServiceHost2Factory" %>
Any help will be appreciated.

Use WebServiceHost2Factory and WebProtocolException for Error Handling
A large part of building an API is ensuring there is adequate error handling in place to help the user implement your API. Up until the release of WebServiceHost2Factory, returning the appropriate HTTP response code and message was a chore. Luckily for us we can achieve this feat quickly and easily by utilising the WebServiceHost2Factory and WebProtocoException classes.
The above text is from the following link
The below help to troubleshoot your problem can be found from the following link.
Parser Error: Service Type Could Not Be Loaded During Compilation
You may get the following error message when you navigate a WCF service (.svc file) from a browser:
The CLR Type 'XXXX' could not be loaded during service compilation. Verify that this type is either defined in a source file located in the application's \App_Code directory, contained in a compiled assembly located in the application's \bin directory, or present in an assembly installed in the Global Assembly Cache. Note that the type name is case-sensitive and that the directories such as \App_Code and \bin must be located in the application's root directory and cannot be nested in subdirectories.
The error message is pretty explainable by itself. However, I still want to point out different situations when this can happen. Here is the format of the Service Directive of a .svc file:
<%#Service language=c# Class="<Managed Type>" [Other attributes] %>
Here are possible reasons why this can happen:
The specified string for the “Class” attribute does not represent an existing CLR type. Sometimes, this may be due to a typo. This string is case-sensitive. Also if you copy this from MS-Word, the quotes may be some special Unicode characters instead of the real ASCII quotes.
If you have the assembly (containing the service type) in the \bin directory, it is possible that you did not create a virtual directory so that its root directory contains \bin as its immediate sub-directory.
If you have your type in a code file under \App_Code, it may be due to the same reason as above.

Related

WCF fails to import WSDL

I'm trying to "Add Service Reference" with WCF to the following wsdl: https://se-face-webservice.redsara.es/sspp?wsdl
The visual studio does not provide any warning but the reference.cs is empty and no serialization took place.
I have already tried removing the "Reuse types in specified referenced assemblies", however the serialization stills fails.
If I tried to add the service with the WcfTestClient it gives an error stating that : 'http://schemas.xmlsoap.org/soap/encoding/Array' is not defined.
Finally, when I add the wsdl through a "Add Web Reference" the serialization takes place. I'm guessing that maybe the service is using "unknown" bindings to WCF.
Is there a work around for this situation?
PS: If I use the SoapUI to generate the client everything works fine.
Your WSDL is faulty. It defines the prefix soap-enc, but does not define the schema which defines it. The WSDL is assuming that the http://schemas.xmlsoap.org/soap/encoding/ schema is automatically defined.
Perhaps this service is built on an old version of Axis? I have seen that version assume that the consumer is also built on Axis.
I've tried good old wsdl.exe for generating web service references with System.Web.Services and seems to work - generating and compilation at least :-)
Can you check it? Link to project on bitbucket. Just simple console app with references and generated assemblies.
https://bitbucket.org/polacekpavel/servicestack_27747564/src
and interesting one - generated proxy class https://bitbucket.org/polacekpavel/servicestack_27747564/src/c43b90221fae7ceb2e234552b9f57034551b3cbf/SSPPWebServiceProxyService.cs?at=master

Unity Configuration in Referenced Assembly not recognized

I have a rather expensive library which I've inherited from another project. This assembly is using interception via Unity and requires an elaborate Web.config for design time configuration. I am attempting to use this assembly from within a MSMQ WCF Service, and I'm receiving errors when the code inside the assembly attempts to open DB connections that are hosted by Enterprise Library.
Resolution of the dependency failed, type =
"ServicesImplementation.EntityMaster.IEntityRepository", name =
"(none)". Exception occurred while: while resolving. Exception is:
InvalidOperationException - The current type,
ServicesImplementation.EntityMaster.IEntityRepository, is an interface
and cannot be constructed. Are you missing a type mapping?
My question, is it required that I assume all configuration responsibilities from my WCF Service, or is this configuration encapsulated within the referenced assembly.
You must include all configuration in your .config file. It is defalult source for application to get it config data. Also notice, that if you host in IIS, you should use web.config, if not(Windows Service or app) - use app.config. It is possible to extract section configuration to another file and reference it from your main config.
For example:
Assembly1 contains service definition and host logic.
Assembly2 actualy hosts Assembly1 service.
In this case all service configuration must reside in Assembly2 *.config file.

Problem with type of service in ServiceHost directive in wcf service

I am developing a simple wcf service for test. When I test this service with my local IIS 7.5, then it works properly. But when I host it in web IIS, I receive this error:
The type 'WcfServiceLibrary1.Service1',
provided as the Service attribute
value in the ServiceHost directive, or
provided in the configuration element
system.serviceModel/serviceHostingEnvironment/serviceActivations
could not be found.
And my ServiceHost is:
<%# ServiceHost Language="C#" Debug="true" Service="WcfServiceLibrary1.Service1" %>
Please help me resolve this problem
Because I couldn't find this suggested in any of the questions I looked through for this, adding my case here:
I had this problem when I manually changed the namespace in the file MyService.svc.cs, and did not change the Service name in the corresponding file MyService.svc - turned out that it needed to be Service="namespace.classname".
Try using the assembly qualified type name.
This is [Fully Qualified Type Name], [Assembly]
Where [Fully Qualified Type Name] is, in the most common cases YourNamespace.YourType
And [Assembly] is, in the most common cases YourAssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
It gets more complicated than this (generic types, nested types etc) - but unlikely to be so in your case.
If your application is using the default build options, then I'm going to hazard a guess that the directive should be something like this:
<%# ServiceHost Language="C#" Debug="true"
Service="WcfServiceLibrary1.Service1,
WcfServiceLibrary1,
Version=1.0.0.0,
Culture=neutral,
PublicKeyToken=null" %>
Although you'll probably want to get rid of the newlines there.
Also, make sure your dll has actually been deployed
I had the same issue only when publishing my service but it worked locally.
It turned out to be that the service was referencing a DLL that wasn't being deployed. It's a super special case because it was a system dll (System.Web.Helpers) and thus the project didn't even have a reference to it and thus the "Copy Local" wasn't set to true.
IIS defaults to expecting to see the svc file in the virtual directory, and the binaries inside a bin folder (as marc_s commented).
However, the default build configuration for WCF Library projects is to build inside a bin/Debug folder (or bin/Release). You can change the Output Path to 'bin/' on the project properties Build tab.
Changing this resolved this error for me today.
I had this same problem after I deployed a working service to a new location (new site) in IIS. In inetmgr under the Default Website tree, I hadn't right-clicked the new site and selected Convert to Application - all working now!
Finally my problem solved.
I removed the service directory in my host and created a new virtual directory in the host space. Then I copied my service in new directory where I created it.
Now I can browse the .svc file for service and my client will consume the service.
I don't understand why this problem occurred! I am a little confused!
The answer marked as answer is very difficult to understand. In fact, although it led me to solve my similar problem, I don't know if that's because I accurately understand what the writer was meaning.
I was finding if I pointed an IIS application on my development machine to the actual project directory in which resides the web.config, MyService.svc, and bin folders necessary for the WCF Service Application it just wouldn't work, and was throwing this error. This is despite quadruple checking every setting and ensuring that things were equivalent to other simple, working WCF Applications.
Ultimately, I solved the problem by publishing to a different directory rather than depending on the project files and directory themselves.
Perhaps it was because the files were open in Visual Studio as I was trying to run the WCF application through IIS? I don't know, but the Visual Studio provided localhost:59871/... was working. I don't know if that instance is using the project files or a temporary published version.
Check whether namespace and class written in "Service" of "SeviceHost" is correct .It should be Service="namespace.classname" .
Another reason for this issue is often when a wcf service is moved from one directory to another, and the svc file has not been updated... easiest solution is to double check your .svc file and make sure the service definition is defined correctly.
As I can't up vote #jeromeyers answer at the moment, I want to add that this is the solution that I found for this issue.
Someone had copied and pasted a svc file and associated contract and code files to a new project, but they had not updated the namespaces and class names everywhere. Very frustrating tracking this down as it started with this error :
" name was started with an invalid character. Error processing resource 'file:///C:/...
<% #ServiceHost "
when trying to right click on the .svc file and doing "View in browser".
Even though this is slightly different than the question (not web iis): I got here through search because I was getting this error trying to Debug my service -- if you have multiple services inside a single solution, this error will occur if the solution in question is not built yet, and therefore the DLL not created when you try to access it. So to anyone out there make sure if running locally that the entire solution is built!
had this problem running a test project that was embedded in my solution.
I had to view in browser, then copy that link to a new service reference (delete the old one) then paste it in rather than using the discover utility button in the service reference.
Strange as well, after looking and trying others suggestions, i was still getting the error saying the:
The type ', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.
Sure we all get large project with a lot of DLLs. Turned out some of the older components in my solution were targeting .Net 4.5, and newer dll were build with 4.5.1. When the 4.5 dlls referenced the 4.5.1 dlls .... Not sure why i was the happy little guinea pig to be the first on my team to find this. While the fix was obvious and easy enough, just all the dlls to target the same .Net runtime.
Just wish Visual Studio would notice DLLs within the same solution should all target the same .Net runtime and generate a warning/error when building especially with we have a solution and a project reference and the runtimes don't match...
Be sure your compiled dlls are moved to service(IIS directory)
directory.
For example, sometimes Jenkins doesn't move them automatically.
I had the same issue when i uploaded my working localhost service to a new location on host.
I create a new Virtual Directory and published my Service to it via Visual Studio(FTP). Problem Solved.
It happend the same to me and the solution was creating a forder named "bin" and place the dll inside of it. Then, refresh the website on IIS and that's all
I had this problem too, and what did the magic for me was to restart the IIS.
This is a very weird error.
First time hosting WCF Service Application, in IIS ?
Many have solved their problems one way or the other. However if everything is your solution is correct and your error is about host your app in IIS, then ensure your physical path in IIS when you add your website is pointed to the "bin" directory of your solution as seen below in the screen shots.
Please look at https://msdn.microsoft.com/en-us/library/ms733766(v=vs.100).aspx
You need to do 2 things to be able to Host the Service on IIS, or even on Visual Studio's itergrated IIS_EXPRESS.
1) Update the Web.Config to include ServiceActivations
change:
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
to
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
<serviceActivations>
<add service="API.Service1" relativeAddress="Service1.svc"/>
</serviceActivations>
</serviceHostingEnvironment>
2) You need to create a directory called App_Code in the root directory.
You now need to move the Service (ex: Service1.svc) from the root directory into the App_Code directory.
So you will have App_Code\Service1.svc
If you browse the Service
http://localhost:63309/Service1.svc it should work.

How to Create WCF proxy class given wsdl file

I have wsdl file with me.But i don't have access to the file where it is deployed.
I need to generate proxy class using the WSDl file. I am getting error while using svcutil.ece to generate proxy file
Error: Cannot import wsdl:port Detail:
Cannot find definition for
http://www.cii.com/Soa/Foundation:Basi
cHttp. Service Description with
namespace
htt://www.cii.com/Soa/Foundat ion is
missing. Parameter name: name XPath to
Error Source:
//wsdl:definitions[#targetNamespace='http://www.cii.com/Soa/Foundation/MessageDefinition.xsd']/wsdl:service[#name='CareerServicesS
ervice']/wsdl:port[#name='BasicHttp']
Thanks,
Shodhan
If you are using svcutil with a locally downloaded WSDL file, you need to also download all related XSD files and pass them on the svcutil command line as well. A great tool for automatically downloading all related XSD files is disco.exe in the Windows / .NET SDK (and there may be a svcutil mode that does it as well, don't remember for sure).

Silverlight Business Application template with WCF is throwing warning

I am using the Silvelight Business Application template. I wrote a function which uses Membership.getUserList function to return the user list. I tried exposing it as Service using WCF. But when I try to compile the client side code it throws a warning saying "Client Proxy Generation for user_authentication.Web.Service1 failed'. Why does it happen?
The complete warning message is:
Warning 4 Client proxy generation for
service
'user_authentication.Web.Service1'
failed: Generating metadata files...
Warning: Unable to load a service with
configName
'user_authentication.Web.Service1'. To
export a service provide both the
assembly containing the service type
and an executable with configuration
for this service.
Details:Either none of the assemblies passed were executables
with configuration files or none of
the configuration files contained
services with the config name
'user_authentication.Web.Service1'.
Warning: No metadata files were
generated. No service contracts were
exported. To export a service, use
the /serviceName option. To export
data contracts, specify the
/dataContractOnly option. This can
sometimes occur in certain security
contexts, such as when the assembly is
loaded over a UNC network file share.
If this is the case, try copying the
assembly into a trusted environment
and running it.
Hard to say, I'm not a good enough clairvoyant yet ;-) ... Is your webservice actually already compiled, published and running? Maybe here you can find further hints:
MSDN WCF Forums: svcutil Error