I have developed a C# WCF client application using Visual Studio 2008 and it works fine. The client application uses the wcf wrapper class and consume the WCF service. But when I execute the same source code in Redhat Linux 6.5 using MonoDevelop IDE, I am getting the following exception while creating a wcf object. The WCF web service is running as a windows service.
{System.NotImplementedException: The requested feature is not implemented. at System.ServiceModel.Configuration.WSHttpBindingElement.OnApplyConfiguration (System.ServiceModel.Channels.Binding binding) [0x00000] in /home/abuild/rpmbuild/BUILD/mono-3.4.0/mcs/class/System.ServiceModel/System.ServiceModel.Configuration/WSHttpBindingElement.cs:101 at System.ServiceModel.Configuration.StandardBindingElement.ApplyConfiguration (System.ServiceModel.Channels.Binding binding) [0x00030] in /home/abuild/rpmbuild/BUILD/mono-3.4.0/mcs/class/System.ServiceModel/System.ServiceModel.Configuration/StandardBindingElement.cs:143 at System.ServiceModel.Configuration.ConfigUtil.CreateBinding (System.String binding, System.String bindingConfiguration) [0x00053] in /home/abuild/rpmbuild/BUILD/mono-3.4.0/mcs/class/System.ServiceModel/System.ServiceModel.Configuration/ConfigUtil.cs:104 at System.ServiceModel.ChannelFactory.ApplyConfiguration (System.String endpointConfig) [0x000e9] in /home/abuild/rpmbuild/BUILD/mono-3.4.0/mcs/class/System.ServiceModel/System.ServiceModel/ChannelFactory.cs:156 at System.ServiceModel.ChannelFactory.InitializeEndpoint (System.String endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) [0x00024] in /home/abuild/rpmbuild/BUILD/mono-3.4.0/mcs/class/System.ServiceModel/System.ServiceModel/ChannelFactory.cs:309 at System.ServiceModel.ChannelFactory1[IMyMonitor]..ctor (System.String endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) [0x00017] in /home/abuild/rpmbuild/BUILD/mono-3.4.0/mcs/class/System.ServiceModel/System.ServiceModel/ChannelFactory_1.cs:73 at System.ServiceModel.ClientBase1[IMyMonitor].Initialize (System.ServiceModel.InstanceContext instance, System.String endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) [0x00000] in /home/abuild/rpmbuild/BUILD/mono-3.4.0/mcs/class/System.ServiceModel/System.ServiceModel/ClientBase.cs:159 at System.ServiceModel.ClientBase1[IMyMonitor]..ctor (System.ServiceModel.InstanceContext instance, System.String endpointConfigurationName) [0x00028] in /home/abuild/rpmbuild/BUILD/mono-3.4.0/mcs/class/System.ServiceModel/System.ServiceModel/ClientBase.cs:90 at System.ServiceModel.ClientBase1[IMyMonitor]..ctor (System.ServiceModel.InstanceContext instance) [0x00000] in /home/abuild/rpmbuild/BUILD/mono-3.4.0/mcs/class/System.ServiceModel/System.ServiceModel/ClientBase.cs:79 at System.ServiceModel.ClientBase`1[IMyMonitor]..ctor () [0x00000] in /home/abuild/rpmbuild/BUILD/mono-3.4.0/mcs/class/System.ServiceModel/System.ServiceModel/ClientBase.cs:54 at SenMonitorClient..ctor () [0x00000] in /mywork/myclient/wcfService.cs:1429 at myclient.start () [0x0079c] in /mywork/myclient/Program.cs:285 } System.NotImplementedException
Environment: MonoDevelop 4.2.3, mono 3.4.0
Thanks for your help.
WCF support is currently limited on Mono and as mentioned here - mono-project.com/WCF WSHttpBinding and its dependencies are components with no plan to support. May be you want to fall back on to basichttpbinding which should be supported since it shows WCF modules were in development till .NET 3.0 with silverlight 2.0 subset.
Related
I am hosting my ASP.NET Core 3 web application in Azure, whenever I do a new publish to Azure, it works as expected. However, the next day, the site is down, then I need to republish again, then it works, then it is down again the following day.
The full error message from Azure is this:
Application '/LM/W3SVC/975757150/ROOT' with physical root 'D:\home\site\wwwroot' hit unexpected managed exception, exception code = '0xe0434352'. First 30KB characters of captured stdout and stderr logs:
Unhandled exception.
Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: Keyset does not exist
at Internal.NativeCrypto.CapiHelper.CreateProvHandle(CspParameters parameters, Boolean randomKeyContainer)
at System.Security.Cryptography.RSACryptoServiceProvider.get_SafeProvHandle()
at System.Security.Cryptography.RSACryptoServiceProvider.get_SafeKeyHandle()
at System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 keySize, CspParameters parameters, Boolean useDefaultKeySize)
at System.Security.Cryptography.RSACryptoServiceProvider..ctor(CspParameters parameters)
at Internal.Cryptography.Pal.CertificatePal.<>c.b__66_0(CspParameters csp)
at Internal.Cryptography.Pal.CertificatePal.GetPrivateKey[T](Func2 createCsp, Func2 createCng)
at Internal.Cryptography.Pal.CertificatePal.GetRSAPrivateKey()
at Internal.Cryptography.Pal.CertificateExtensionsCommon.GetPrivateKey[T](X509Certificate2 certificate, Predicate1 matchesConstraints) at System.Security.Cryptography.X509Certificates.RSACertificateExtensions.GetRSAPrivateKey(X509Certificate2 certificate) at Microsoft.IdentityModel.Tokens.X509SecurityKey.get_PrivateKey() at Microsoft.IdentityModel.Tokens.X509SecurityKey.get_PrivateKeyStatus() at Microsoft.Extensions.DependencyInjection.OpenIddictServerBuilder.AddSigningKey(SecurityKey key) at Microsoft.Extensions.DependencyInjection.OpenIddictServerBuilder.AddSigningCertificate(X509Certificate2 certificate) at ackids.Startup.<ConfigureServices>b__6_6(OpenIddictServerBuilder options) in D:\ackidsRepos\ackids\ackids\Startup.cs:line 154 at Microsoft.Extensions.DependencyInjection.OpenIddictServerExtensions.AddServer(OpenIddictBuilder builder, Action1 configuration)
at ackids.Startup.ConfigureServices(IServiceCollection services) in D:\ackidsRepos\ackids\ackids\Startup.cs:line 118
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.g__Startup|0(IServiceCollection serviceCollection)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.b__0(IServiceCollection services)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass12_0.b__0(HostBuilderContext context, IServiceCollection services)
at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
at Microsoft.Extensions.Hosting.HostBuilder.Build()
at ackids.Program.Main(String[] args) in D:\ackidsRepos\ackids\ackids\Program.cs:line 16
Process Id: 14164.
File Version: 13.1.21196.18. Description: IIS ASP.NET Core Module V2 Request Handler. Commit: 0a2e366eaf4d29b24b9a98e5782a04bef573189e*
The reason for this error might be the The OpenIddict versions that you are using which are not compatible for ASP.NET 3.1.
Try upgrading to the latest versions.
I have a MVC website, which using Dependency Injection "Unity", it is running fine on my local machine and also no problem on my old dedicated server (Window SEVER 2008 R2 SP1). When I move the website to Azure VM (Window SEVER 2008 R2 SP1), I got following error message;
Server Error in '/' Application.
The IControllerFactory 'Store.Factories.UnityControllerFactory' did not return a controller for the name 'Home'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The IControllerFactory 'Store.Factories.UnityControllerFactory' did not return a controller for the name 'Home'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: The IControllerFactory 'Store.Factories.UnityControllerFactory' did not return a controller for the name 'Home'.]
System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +423
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +73
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +921
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +137
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1055.0
I cannot figure out why, Any help?
The problem was solved automatically by upgrading Unity from 2 to 4.
I need to run a .net C# application (developed on a Windows system) as a service/daemon on an embedded system with a minimal Ubuntu installation (no X, no servers except ssh, only relevant software). I created an /etc/init.d script containing the line
mono-service my-.net-app.exe service
and this worked well. There is also an option to start the application interactively (for debugging purposes) with
mono my-.net-app.exe interactive
The last argument is an argument for the .NET application telling it if it's running as service. This was implemented roughly this way:
private static void Main(string[] args){
if(args.Any() && args[0] != null && args[0] == "service"){
ServiceBase.Run(new[] {(ServiceBase) new MyService()});
}else{
try{
Console.Write("starting app");
if(StartWork()){
Console.Write("press any key to exit");
Console.ReadKey();
}else{
Console.WriteLine("starting app failed");
}
} // end try
finally{
StopWork();
Console.WriteLine("finished app");
}
} // end else
...
} // end Main
public class MyService : ServiceBase{
static private Thread _worker;
protected override void OnStart(string[] args){
_worker = new Thread(() => Program.StartWork(asService: true)); // this asService tells StartWork to not produce console output
_worker.Start();
}
protected override void OnStop(){
Program.StopWork();
_worker.Join(1000);
}
}
The purpose of this implementation was to allow the application to die gracefully (i.e. to execute StopWork()) upon sending SIGTERM on the linux machine.
For security reasons, I need to be able to run the service as non-root. I created a new user and made it owner of the directories where the application writes its log files and added it to various groups to give it access to required device files. Then, root would start the application as
sudo -u newuser mono-service my-.net-app.exe service
or
sudo -u newuser mono my-.net-app.exe interactive
The second option with mono works well, but the first one with mono-service doesn't (see error message below). Since it works with mono, I'm confident that the user newuser has appropriate rights to access all relevant files and devices. I wonder whether mono-service has been conceived as a root-only application.
I could also live with using the mono option and suppressing the console output, like this:
private static void Main(string[] args){
try{
Console.Write("starting app");
if(StartWork(consoleoutput)){ // true or false depending on whether the service argument was given
Console.Write("press any key to exit");
Console.ReadKey();
}else{
Console.WriteLine("starting app failed");
}
} // end try
finally{
StopWork();
Console.WriteLine("finished app");
}
...
} // end Main
but then, when I kill the service (i.e. send SIGTERM to the mono process), it stops the .net application immediately without allowing it to execute the finally block.
Finally, my question is whether someone has an idea why mono-service is failing when not started as root. The error message is the following and, as I mentioned before, it doesn't exist when I use mono instead of mono-service.
ERROR Program [4] [15:03:06.795 01/12/14] Error in Main!
FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
---> NHibernate.HibernateException: Could not create the driver from SAFEmine.DataStore.Database.MonoSqliteDriver, SAFEmine.DataStore, Version=1.3.0.6, Culture=neutral, PublicKeyToken=null. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> NHibernate.HibernateException: The IDbCommand and IDbConnection implementation in the assembly Mono.Data.Sqlite could not be found. Ensure that the assembly Mono.Data.Sqlite is located in the application directory or in the Global Assembly Cache. If the assembly is in the GAC, use <qualifyAssembly/> element in the application configuration file to specify the full name of the assembly.
at NHibernate.Driver.ReflectionBasedDriver..ctor (System.String providerInvariantName, System.String driverAssemblyName, System.String connectionTypeName, System.String commandTypeName) [0x00000] in <filename unknown>:0
at NHibernate.Driver.ReflectionBasedDriver..ctor (System.String driverAssemblyName, System.String connectionTypeName, System.String commandTypeName) [0x00000] in <filename unknown>:0
at SAFEmine.DataStore.Database.MonoSqliteDriver..ctor () [0x00000] in <filename unknown>:0
at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&)
at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00000] in <filename unknown>:0
Alternatively, if I settle for mono instead of mono-service, is there a way to catch a SIGTERM from within the .net application and to die gracefully? I tried this: https://github.com/ServiceStack/ServiceStack/wiki/Run-ServiceStack-as-a-daemon-on-Linux , but the code wouldn't compile on Visual Studio saying that the using Mono.Unix; and using Mono.Unix.Native lines were invalid. I also installed Mono on Windows and tried to use the Mono compiler, but it complained about the same thing.
The mono-service.exe creates a new AppDomain with ApplicationBase being the current directory. This might influence assembly loading. Since you are seeing such an error, I would try to enable MONO_LOG_LEVEL=debug MONO_LOG_MASK=asm and/or strace -e file to see if they provide any hints.
Also note that you can pass -d switch to mono-service to have it change directory for you.
I create HttpClient and call GetStringAsync method right at the button click handler:
var client = new HttpClient();
var response = await client.GetStringAsync("http://google.com");
Debug.WriteLine("Response received: {0}", response);
And every time I get the following error:
System.InvalidOperationException: Operation is not valid due to the current state of the object
2014-05-10 01:26:36.657 HelloWorld3[490:60b] Unhandled managed exception: Operation is not valid due to the current state of the object (System.InvalidOperationException)
at System.Lightup.Call[HttpWebRequest,Int64] (System.Delegate& storage, System.Net.HttpWebRequest instance, System.String methodName, Int64 parameter) [0x00000] in <filename unknown>:0
at System.Lightup.Set[HttpWebRequest,Int64] (System.Delegate& storage, System.Net.HttpWebRequest instance, System.String propertyName, Int64 value) [0x00000] in <filename unknown>:0
at System.Net.HttpWebRequestLightup.SetContentLength (System.Net.HttpWebRequest instance, Int64 value) [0x00000] in <filename unknown>:0
at System.Net.Http.HttpWebRequest.set_ContentLength (Int64 value) [0x00000] in <filename unknown>:0
at System.Net.Http.HttpClientHandler.StartRequest (System.Object obj) [0x00000] in <filename unknown>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispat
chInfo.Throw () [0x0000b] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:62
at System.Runtime.CompilerServices.TaskAwaiter`1[System.String].GetResult () [0x00000] in <filename unknown>:0
at HelloWorld3.MyViewController+<<ViewDidLoad>b__0>d__1.MoveNext () [0x00029] in c:\Sources\Local\HelloWorld3\HelloWorld3\MyViewController.cs:41
Debugging session ended.
The program 'Mono' has exited with code 0 (0x0).
I'm not using portable libs, nugets, etc. Just plain project created from a template.
How to solve this issue?
test project with reproduced issue here:
https://dl.dropboxusercontent.com/u/19503836/HelloWorld3.zip
In general this happens when you're building your application using PCL assemblies and from Windows.
I'm not using portable libs,
Ok, still you're likely falling into the same situation. You have the wrong (MS not XI) version of System.Http.Net.dll being copied (and compiled) on the Mac. E.g.
at System.Lightup....
Is not part of the assembly being shipped with Xamarin.iOS. Having this in your stack trace is an indication that the wrong assembly is being used.
This is a known issue that is being fixed (at least for the PCL part). In the mean time the general workaround is using a redirect file (see James blog) or build from the Mac.
In your specific case you might just need to ensure the right assembly is being referenced.
i had the same problem!
resolve with FlorianZimmermann solution.
on this link:
https://forums.xamarin.com/discussion/36713/issue-with-microsoft-http-net-library-operation-is-not-valid-due-to-the-current-state-of-the-objec
right-click on References directory for ios or android solution
select edit references
in packages tab , check System.Net.Http
build!
Hope it's help.
Another workaround would be to wrap up your web request in a service that gets injected into the PCL.
Not ideal but thats what Im doing for now.
Before getting into major complications with platform specific "simple" handlers and IoC magic, I suggest you validate a couple of things. After all the whole point of Xamarin and Mono are to avoid all these black santeria hacks to begin with.
If this doesn't work, I would then science the shit of it, and go ballistic... but start here first:
Make sure your platform specific project (MyProject.iOS, or MyProject.Android) HAVE the System.Net.Http referenced under references
Make sure your PCL is targeting the a Profile that is supported by your platform specific project targets (as of the time of this writing, I use "PCL 4.5 - Profile78" with iOS and Android projects)
Good luck!
Hy guys ,
I developed a WebForms application using VS 2012 . I've published it on Azure .
After that I integrated ACS ( i've set the URL to my allready published application)
I published the application again , but it doesn't work .
After I've registered myself (for ex using Yahoo or LiveID) I've got this error :
Server Error in '/' Application.
The data protection operation was unsuccessful. This may have been caused by not having the user profile loaded for the current thread's user context, which may be the case when the thread is impersonating.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Security.Cryptography.CryptographicException: The data protection operation was unsuccessful. This may have been caused by not having the user profile loaded for the current thread's user context, which may be the case when the thread is impersonating.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[CryptographicException: The data protection operation was unsuccessful. This may have been caused by not having the user profile loaded for the current thread's user context, which may be the case when the thread is impersonating.]
System.Security.Cryptography.ProtectedData.Protect(Byte[] userData, Byte[] optionalEntropy, DataProtectionScope scope) +379
System.IdentityModel.ProtectedDataCookieTransform.Encode(Byte[] value) +52
[InvalidOperationException: ID1074: A CryptographicException occurred when attempting to encrypt the cookie using the ProtectedData API (see inner exception for details). If you are using IIS 7.5, this could be due to the loadUserProfile setting on the Application Pool being set to false. ]
System.IdentityModel.ProtectedDataCookieTransform.Encode(Byte[] value) +167
System.IdentityModel.Tokens.SessionSecurityTokenHandler.ApplyTransforms(Byte[] cookie, Boolean outbound) +57
System.IdentityModel.Tokens.SessionSecurityTokenHandler.WriteToken(XmlWriter writer, SecurityToken token) +658
System.IdentityModel.Tokens.SessionSecurityTokenHandler.WriteToken(SessionSecurityToken sessionToken) +86
System.IdentityModel.Services.SessionAuthenticationModule.WriteSessionTokenToCookie(SessionSecurityToken sessionToken) +144
System.IdentityModel.Services.SessionAuthenticationModule.AuthenticateSessionSecurityToken(SessionSecurityToken sessionToken, Boolean writeCookie) +82
System.IdentityModel.Services.WSFederationAuthenticationModule.SetPrincipalAndWriteSessionToken(SessionSecurityToken sessionToken, Boolean isSession) +216
System.IdentityModel.Services.WSFederationAuthenticationModule.SignInWithResponseMessage(HttpRequestBase request) +860
System.IdentityModel.Services.WSFederationAuthenticationModule.OnAuthenticateRequest(Object sender, EventArgs args) +369
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +136
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69
What should i do ?
I've set the URL's correctly. I don't have in web.config any reffernces of "localhost"..
I don't know what I must set additionly for this to work..
By default WIF uses DPAPI to encrypt cookies. Switch to cert based encryption. See this answer:
Is it possible to run WIF without LoadUserProfile = True
Vittorio Bertocci answers the question here
http://www.cloudidentity.com/blog/2013/01/28/running-wif-based-apps-in-windows-azure-web-sites-4/
DPAPI is not available in the cloud web apps and 4.5 has a simple solutions