wcf service message based activation getting a strange error - wcf

I developed a basic wcf service using just a .svc file, and a library
If I call the service via debug it shows me a page with some links , between which I find my .svc file : when I click on it I get the following error message :
Name cannot begin with the '%' character, hexadecimal value 0x25. Line 1, position 2.
The .svc file contains the following :
<%#ServiceHost Language="C#" Debug="true" Service="WcfServiceMessageBasedActivationLibrary1.Service1" %>
where WcfServiceMessageBasedActivationLibrary1.Service1 is the library containing the real implementation.
If I create an application on IIS pointing to the same folders , I get the same error.
The error message is nonsense to me, since there is no "name" starting with "%" in any part of the source code.
I tried every option that was humanly possible , without any effect.
What is the cause of the problem ?

Related

URL /%20/ throws configuration file error with external connectionStrings or appSettings files

Had some pen testers test an ASP.NET MVC4 site, and they found I was showing a "raw" error with the URL: /%20/ e.g. https://example.com/%20/
Server Error in '/' Application.
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: The configSource file 'Web_ConnectionStrings.config' is also used in a parent, this is not allowed.
Source Error:
Line 17: <!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->
Line 18: <!-- these settings can be found in external files - this prevents application restart when they are changed -->
Line 19: <connectionStrings configSource="Web_ConnectionStrings.config" />
Line 20: <appSettings configSource="Web_AppSettings.config" />
Line 21: <!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->
Although it should be, this isn't a normal 404 error, I already catch those and display a custom page. I also catch 500's and display them nicely too. This error happens earlier than the Application_Error() in global.asax.cs so it's not caught there.
This seems to be caused by the slash-space-slash confusing IIS or the application, and it's trying to load the web.config's include files more than once or something.
If I include those sections the normal way (not external files - just normal XML sections in the web.config) then everything works as expected and the custom 404 page shows.
If you removed the %20 and just do two slashes, everything works fine. It seems like it has to be this specific URL.
I've seen other posts about IIS configuration with Default Site or virtual paths pointing to the same file location. But I don't think that applies, as I have the Default Site stopped, and I don't see any problems on any other URLs - the site seems to be working fine.
Does anyone know what IIS is trying to do with a /%20/ URL? Or how to handle this more gracefully?
I like having these config sections split out so changes don't recycle the app pool, but if this is a problem with doing this (why are external files allowed then?) then I guess I'll bring all the settings into the web.config itself.

Must use exact identifier for APP object with verb SET

I'm following this article on allowing WCF to read data from MSMQ but am getting an error with this command
appcmd set app "MSMQ/MsmqService" /enabledProtocols:net.msmq
MSMQ is the name of my IIS hosted website and MsmqService is the name of the .svc file.
The error I get is
ERROR ( message:Must use exact identifer for APP object with verb SET. )
Here is what my site looks like in IIS
I ran into this today, so here's the fix for the "Exact Identifier" error:
Change
"MSMQ/MsmqService"
To
"MSMQ/MsmqService/"
appcmd simply expects a path that includes a slash at the end (exact identifier).
#Sachin, All you are trying to perform by running this command is to set net.msmq in the enabled protocols of the virtual directory. In this specific command the MsmqService is the name of the vDir under your web site MSMQ. If you create a vDir with name MsmqService and execute this command the command will succeed (not the svc file name). And svc files should have the .svc extension for IIS to be able to invoke the appropriate handlers when a request arrives.
Alternatively you can do the same thing in IIS UI following these instructions:
inetmgr from run prompt
Go to the web site MSMQ
Navigate to the vDir MsmqService. Right click -> Manage application -> "Advanced settings..."
Notice a setting named "Enabled Protocols". Type in net.msmq there. Hit OK.

Use of WebServiceHost2Factory

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.

WCF Service Reference issue on production in console application

I have 1 c# Console Application project, which has Program.cs (that contains main method), the main method simple calls a web service method and displays the string on the console.
The service reference is added in the project by right clicking it and adding service reference it to it.
when the console application is executed in debug mode from visual studio, it works as expected.
when the console application is executed from a .exe found in /bin/debug, it works as expected.
so far so good.
PROBLEM:
when the project is copied over to the system (you can call it a production environment), where this .exe will actually be executed, it fails at the exact line where i create the service proxy object. the line in Program.cs is:
ProjectName.ServiceReference.ServiceClient service = new ProjectName.ServiceReference.ServiceClient();
I know it fails here, because i have Console.Writeline("some line"); before and after the above line. I can see the Console.Writeline that is before the proxy line, and soon after that it crashes ...
I think this is because the reference paths that are referencing the service, is there any thing i can do to change the paths, or confirm that it is the path issue as suspected ...??
any idea whats going wrong ..???
Check this link: http://blog.davidsandor.com/post/Workaround-The-configuration-for-the-servicee280a6Unrecognized-element-e28098extendedProtectionPolicye28099.aspx
The configuration for the service reference could not be updated due
to the following issue: Unrecognized element
‘extendedProtectionPolicy’. (App.config / Web.config)
There does not seem to be a really clear reason why this is happening
however it seems to be related to Windows 7. I am not sure if the
.NET framework that ships with Win7 has some different setting or
template for the WCF configuration policy files but it seems to be the
culprit. Maybe the machine.config files are different on Win 7 and
the WCF configuration tools use the machine.config as some sort of
policy template.
The fix is annoying (because every time you build your solution on
Windows 7 and then rebuild on Vista you have to redo this).
Remove the line:
<extendedProtectionPolicy policyEnforcement="Never" />
from both your App/Web.config file on the client and on the WCF
server’s Web.config file.

WCF Difference in two URLs that point to the WSDL

URL in browser: http://localhost:12345/FRB.EC.BMI.WebSvc/Datafaction.svc
shows this:
You have created a service.
To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax:
svcutil.exe http://sfbztkdev01v.biztalkdev.corp.firstrepublic.com:12345/FRB.EC.BMI.WebSvc/Datafaction.svc?wsdl
Why does the URL in the "svcutil" line often differ from what is in the URL, and how do I change it? I think there is an attribute to add to my code? Or is there any reason to even be concerned that they are different.
In my specific case, I'm on a VMWare image that has no internet access, and I'm using the port number to avoid conflicts with SharePoint. When I click on the URL on the svcutil line it loads okay in the browser. But in SOAP-UI, I'm not getting any response to either that URL or the URL I first mentioned above with "?wsdl" added to the end.
Thanks,
Neal Walters
Update:
Soap-UI is getting hung on this URL - which it finds inside the above WSDL.
<wsdl:import namespace="http://FRB.EC.BMI.WebSvc/" location="http://sfbztkdev01v.biztalkdev.corp.firstrepublic.com:12345/FRB.EC.BMI.WebSvc/Datafaction.svc?wsdl=wsdl0" />
Even when I save WSDL to file and use that file with SOAP-UI, SOAP-UI is still trying to load the second =wsdl0 from IIS. It is not getting error nor response. It just keeps looking for several minutes until I hit cancel. When I paste same URL with =wsdl0 in URL of browser it opens fine (and then has three more xsd's internal that will have to be opened).
Also please note that I am also trying WCFTestClient.exe and it accepts the URL but when I click the Invoke button gives this:
Could not connect to
http://sfbztkdev01v.biztalkdev.corp.firstrepublic.com:12345/FRB.EC.BMI.WebSvc/Datafaction.svc. TCP error code 10065: A socket operation was attempted to an unreachable host 192.168.159.129:12345.
(I'm not yet sure where the above IP address is coming from.)
?wsdl at the end is fine, it is always added. If you can open it in browser just save the wsdl file then open it in SOAP UI