Over a year ago I had been working on a WCF service, which I wrote using VS 2008. It runs under a Windows service, which I also wrote. It’s been running there ever since. And unfortunately, other projects/priorities have come up, preventing me from continuing with that project, until now.
Now I’m trying to get back to it. However, this go around I’m trying to find out if I can use VS 2010 and .NET 4, instead of .NET 3.5. I’ve brought up the command prompt, to run SvcUtil, to get the wsdl information, which I’ll put into the config file for the new WPF app I’m trying to get started writing. Only thing is, I keep getting an error, saying that I can’t reach the server, etc.
So, I copied the .exe.config file from the server to my machine, where I could edit it with SvcConfigEditor. I’ve made those changes, put it back onto the server, and got an error while trying to run SvcUtil, but worse than that I didn’t see the .svclog files I expected to see. So I got into the server’s Services app. I found the Windows service I wrote a year ago; saw that it was running, and stopped and started it again.
Now I’ve got a different problem. My Windows service starts, but then stops immediately. I get this message saying that the service had started and then stopped, and saying that sometimes that happens with different sorts of services, like Performance Logs and Alerts services. I’ve checked the event log on the server, and then only thing there related to this Windows service is that it entered the start state and then entered the stopped state.
Ah, after attempting to start it 4 times, it finally gave me an error in the event log! (Why didn’t it do that in the first place? And who says that trying to do the same thing over and over again, and expecting different results is a sign of insanity, when clearly the first 3 times it didn’t register anything in the event log, but on the 4th try it did.)
Here’s the error:
Event Type: Error
Event Source: Service1
Event Category: None
Event ID: 0
Date: 5/4/2011
Time: 10:14:46 AM
User: N/A
Computer: HELIOS
Description:
Service cannot be started. System.TypeInitializationException:
The type initializer for 'System.ServiceModel.DiagnosticUtility'
threw an exception. --->System.Configuration.ConfigurationErrorsException: Couldn't find type
for class System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089.
at System.Diagnostics.TraceUtils.GetRuntimeObject(String className, Type baseType,
String initializeData)
and here’s the new section of code put into the .config file by SvcConfigEditor:
<sharedListeners>
<add initializeData="C:\Program Files\ASIWindowsService\ASIWindowsService_tracelog.svclog"
type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="ServiceModelTraceListener" traceOutputOptions="Timestamp">
<filter type="" />
</add>
<add initializeData="C:\Program Files\ASIWindowsService\ASIWindowsService_messages.svclog"
type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
<filter type="" />
</add>
</sharedListeners>
This question was answered in the comments but there is a gotcha that I've seen in Visual Studio 2010 that could result in a similar situation.
Even if the target framework is set to version 3.x for a WCF project, using the 2010 SvcConfigEditor will automatically insert "System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0..." although it should be inserting "System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0..." This will bite you when deploying the altered web.config to an IIS hosted service where the AppPool is not configured to use the .NET 4.0 framework. The fix is simply edit the web.config back to "Version=2.0.0.0".
Related
I have an ASPNET Core project that is running a set of RESTful services using C# and Newtonsoft.JSON 11.0.2 which I incorporated using NuGet. When I run everything locally using Visual Studio 2017 and IIS Express, things work fine and my JSON Deserializer efforts work with no issue.
When I publish the solution in a Web Deploy package and then install that application in IIS 10 on a Windows Server 2016 instance in AWS, the deserializer fails. The error is:
Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0
It does not matter if I publish in Debug or Release mode.
I ran Postman calls and the JSON being returned is both validate and produces the correct objects. I did see that, in the Solution Explorer, the version is 11.0.2 but in the assets JSON file, the version is pointed to 10.0.1. The .CS project file, when viewed in a text editor outside of Visual Studio, does show 11.0.2.
When I look in the deployed application's folder on the server, I do not see any NewtonSoft DLLs but I do see other NuGet-obtained DLLs. This might not be an issue given how JSON.NET deploys but I thought it was worth mentioning.
I then included a logger and sent the incoming JSON to a file and, again, it all validated as expected.
I have tried everything, ensured CORS is properly implemented both in the application and in IIS. I am at a complete loss as to how to proceed.
Can somebody please help?
Thank you!
I had the same problem and solved by this code in web.config
<system.webServer>
<handlers>
<remove name="WebDAV" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
<modules>
<remove name="WebDAVModule" />
</modules>
</system.webServer>
I sometimes browse old question that has no/accepted answers and check if they are still in need of some help, or if something can be done to close the cold case.
This post has already been solved, but the cause and the solution were left only in the comments.
If the first character encountered when parsing is <, you can be sure
that is not JSON. Something is probably sending XML or HTML to your
code in the deployed environment. I would look at that angle. This
doesn't seem like a version conflict to me, otherwise you would be
getting a much different error about not being able to load the file
or assembly. I think this is solely a data problem.
Brian Rogers
#Brian Rogers - Thank you SO MUCH for this last comment. I ended up
opening Production to my development machine and then running
Wireshark to see the communications. Turns out that IIS had "GEWT"
instead of "GET" in the allowed methods web.config for the host
website and I was getting rejections in the cloud instead of the JSON.
Every test I ran which generated output was LocalHost but, of course,
none of the real production work used anything local. Once I fixed
that error, everything worked great!
Ken Tola
#ken-tola, can you please self-answer the question and then accept it to close the case.
I'm currently using the CMS Umbraco for my website to handle my blog. While suddenly the login won't work for any user.
UmbracoTracelog
Event Id: 0, state: Login attempt failed for username test from IP
address 127.0.0.1
I've checked my MSSQL where all instances are running and connecting
correctly to my project.
I've tried the UmbracoAdminReset.dll but it doesn't make any
difference.
I've tried to manually change the password in the MSSQL Umbraco users
table with the same login attempt failed error
I've tried to login on different user and still gets the same error
I've built i have restarted the computer but the error still applies, this worked earlier today, All i have done is just working with Disqus comment API on their website.
I've noticed in my Web.config that i have errors in (I manually replaced the PublicKeyToken here with *******)
<sessionState mode="InProc" customProvider="DefaultSessionProvider">
<providers>
<add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=***************" connectionStringName="DefaultConnection" />
</providers>
</sessionState>
Invalid module qualification: Failed to resolve assembly System.Web.Providers
Cannot Resolve symbol DefaultSessionStateProivder
The website runs fine, I get to the login page, I just cannot login because I get Login attempt failed error.
EDIT:
In my Errorlist i can see 28 messages that says:
Could not find schema information for element __
UmbracoConfiguration
security
settings
and 25 more with the same.
It seems like you are missing the DLL for 'System.Web.Providers' OR you are using a different version.
If you publish from Visual Studio, ensure you have set 'CopyLocal' to TRUE if your project references this DLL.
You could also just try to FTP the missing file up to your hosting account.
Let me know how it goes.
Regards
Craig
I've seen several posts about this, but none of the answers seem to work.
I'm trying to set up simplemembership and I keep getting this error when WebSecurity.InitializeDatabaseConnection(...) is called
Here is the ConnectionsStrings entry:
<add name="JBarterMain" connectionString="Data Source=winsrv01;Initial Catalog=ProvausioJBarter;Persist Security Info=True;User ID=xxx;Password=xxx" providerName="System.Data.SqlClient"/>
I tried adding the following to my machine config in the .net 4.0 x64 folder:
<add name="SqlClient Data Provider" invariant="System.Data.SqlClient" description=".Net Framework Data Provider for SqlServer" type="System.Data.SqlClient.SqlClientFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
I'm getting absolutely nowhere. This seems incredibly odd to me that this wouldn't work out of the box. I had another project a few months ago (broken currently so I can't verify that it still works) that was working just fine and I didn't have to do any additional configuration.
Any ideas?
I wrote a tutorial on how to set up simple membership Here. Also I prefer to ditch the filters and initialize it directly on application start
Receiving this error when trying to work with the queue:
Unexpected error occured: The communication object, System.ServiceModel.ServiceHost, cannot be used for communication because it is in the Faulted state.
at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)
How to overcome it?
Update: answer to my solution posted at the end
This problem is due to access rights. Start Visual Studio with administrative rights and the problem will be resolved.
To start Visual Studio with admin rights right click the Visual Studio icon and select "Run As Administrator".
Update: In my case what helped was:
1) enabling trace logs: http://msdn.microsoft.com/en-us/library/ms732023.aspx
2) in the trace log it wrote this:
Binding validation failed because the binding's ExactlyOnce property is set to true while the destination queue is non-transactional. The service host cannot be opened. Resolve this conflict by setting the ExactlyOnce property to false or creating a transactional queue for this binding.
The answer says it all. Created a transactional queue - everything works :) hope it helps people :)
close your solution, Now follow these steps:
1. Right click on the visual studio.
2. Click on Run as Administrator.
3. Now open your solution.
4. Try running it, your problem will be resolved.
From my experience, once a endpoint is in a faulted state, it will not recover on its own and needs to be restarted. There's no way to make that happen from the client side. The host must do it.
On the host side, you can check for a faulted state using code like this:
While True
'broken connection case
If objServiceHost(ii).State <> CommunicationState.Opened Then
Throw New Exception("SynchronizationWS Service Host failed.")
Exit While
End If
Next
Threading.Thread.Sleep(c_SleepTime) 'sleep 1 second before going trying next
End While
We have a higher level program that monitors the heartbeat of our web service (which runs within a windows service) and if the higher level program finds that the heartbeat has stopped, it will recycle the windows service, restarting the WCF web service.
For me it's because the port was already used by another process, I changed the port and the service worked as usual. I knew this by following the trace logs, just follow steps here: https://learn.microsoft.com/en-us/dotnet/framework/wcf/service-trace-viewer-tool-svctraceviewer-exe
The recap:
add this section to the web.config or app.config file:
<system.diagnostics>
<trace autoflush="true" />
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
<listeners>
<add name="sdt"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "SdrConfigExample.e2e" />
</listeners>
</source>
</sources>
</system.diagnostics>
run the WCF service to reproduce the error.
open SvcTraceViewer.exe tool, I found it in :
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin. It will open the Microsoft Service Trace Viewer window.
Navigate to the log file (File> Open) named "SdrConfigExample.e2e" which was specified in the XML config above, and is located in the root directory. This will list the errors in more detail and you can find the cause of the exception.
*Tip: You can easily and quickly find files on your computer using everything tool.
I'm try to work on WCF to sync the mobile database with server database. I was using this tutorial. When i try to debug I got 'File or assembly name 'System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=3BE235DF1C8D2AD3', or one of its dependencies, was not found.'. I try to remove the reference and add again but still the same.
Below is the screen short of System.Sata.SqlServerCE.