I had an asmx service in .NET Framework 3.5 which I have now converted to .NET Framework 4.0. Now I want to run this service as WCF service with the same ASMX extension. I read a couple of blogs which have step y step procedure to convert them. However they all refer to .NET Framework 3.5. Here are the references I got from internet.
http://weblogs.manas.com.ar/waj/2007/05/31/asmx-to-wcf-migration/
http://blogs.msdn.com/b/wenlong/archive/2007/09/18/how-to-use-asmx-extension-to-handle-wcf-requests.aspx
I tried these and they work well with 3.5 framework but not with 4.0 framework. I got the error
Unable to cast object of type
'System.Web.Compilation.BuildResultCustomString'
to type
'System.Web.Compilation.BuildResultCompiledType'.
on which I added httpHandler section and it was gone. However now I get a new error
Could not load type
'System.ServiceModel.Activation.HttpHandler'
from assembly 'System.ServiceModel,
Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089'
Can anyone help me out with this error.
I got it working with aspNetCompatibilityEnabled set to 'true' like this:
Add a reference to:
System.ServiceModel.Activation
in your web.config:
<system.web>
<compilation debug="true" targetFramework="4.0">
<buildProviders>
<remove extension=".asmx"/>
<add extension=".asmx" type="System.ServiceModel.Activation.ServiceBuildProvider, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</buildProviders>
</compilation>
</system.web>
<system.webServer>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated"/>
<add name="MyNewAsmxHandler" path="*.asmx" verb="*" type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</handlers>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
mind the type and publickeytoken changes in the handler! It has to be 'System.ServiceModel.Activation' in stead of 'System.ServiceModel' and 'PublicKeyToken=31bf3856ad364e35' as Microsoft has split these into seperate assemblies
I think you may need to register the .NET 4 handlers in IIS properly. Run ServiceModelReg.exe -ia from the .NET 4 framework directory and see if it helps.
C:\Windows\Microsoft.NET\Framework\v4.0.30319>ServiceModelReg.exe /?
Microsoft (R) WCF/WF registration tool version 4.0.0.0
Copyright (c) Microsoft Corporation. All rights reserved.
Administration utility that manages the installation and uninstallation of
WCF and WF components on a single machine.
Usage:
ServiceModelReg.exe [(-ia|-ua|-r)|((-i|-u) -c:<command>)] [-v|-q] [-nologo]
[-h]
-ia
Install all components
-ua
Uninstall all components
-r
Extended only. Repairs all components
-i
Install components specified with -c
-u
Uninstall components specified with -c
-c:<component>
Install/uninstall a component:
httpnamespace - HTTP namespace reservation
tcpportsharing - TCP port sharing service
tcpactivation - TCP activation service (unsupported on .NET 4 Clien
t Profile)
namedpipeactivation - Named pipe activation service (unsupported on .NET
4 Client Profile)
msmqactivation - MSMQ activation service (unsupported on .NET 4 Clie
nt Profile)
etw - ETW event tracing manifests (Windows Vista or later
)
Can be used to install several components at the same time
-q
Quiet mode (only error logging)
-v
Verbose mode
-nologo
Suppress the copyright and banner message
-h
Displays this help text.
Examples:
ServiceModelReg.exe -ia
Installs all components
ServiceModelReg.exe -i -c:httpnamespace -c:etw
Installs HTTP namespace reservation and ETW manifest
ServiceModelReg.exe -u -c:etw
Uninstalls ETW manifests
ServiceModelReg.exe -r
Repairs an extended install
Related
I'm trying to use HttpClient on a VB.NET page (Windows Server 2019 IIS 10), but getting BC30002 error. Tracing the error in IIS, I see warning BC40056 (Namespace not found) on line:
Imports System.Net.Http
Running gacutil, seems that the assembly is correctly installed on server:
>gacutil.exe /l system.net.http
Microsoft (R) .NET Global Assembly Cache Utility. Version 4.0.30319.0
Copyright (c) Microsoft Corporation. All rights reserved.
The Global Assembly Cache contains the following assemblies:
system.net.http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL
Number of items = 1
Also tryed to add the following to web.config (should not be necessary and didn't help):
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Other assemblies load fine (including plain System.Net).
Where am I wrong ?
Finally understood that, even if .NET Framework 4.8 supports HttpClient, CLR is still at 4.0 version (that don't support HttpClient).
Optimal solution, as noted by user9938, would be migrating to .NET 6, but, for an old app where I just need to add a small integration, was easier for me to use old WebClient, instead of HttpClient. This works like a charm:
Imports System.Net
...
Using client As New WebClient()
BackJson = client.DownloadString(APIUri)
End Using
WebClient is still supported (as of .Net 6.0.6), even if not recommended for new development.
I can't find anything to resolve this and have tried multiple things.
Task: I am trying to add bundles to an old existing web project. I have added everything I need I believe as I have done the same in a new project and it works.
<webopt:BundleReference runat="server" Path="~/bundles/masterstyle" />
This seems to be where the issue has started with this line above. I installed via nuget the web optimization webforms package which fixed the squiggly line under webopt. However, now, I am getting 2 issues.
BundleReference has a squiggly line saying "Element
'BundleReference' is not a known element/ This can occur if there is
a complication error in the Web site, or the web.config file is
missing".
It also can't seem to find the package I have just installed which
is "Could not load file or assembly
'Microsoft.AspNet.Web.Optimization.WebForms' or one of its
dependencies. The system cannot find the file specified".
If anyone can help resolve this, it would be greatly appreciated. Been stuck on it for 4 hours now.
Here is the likely relevant stuff in my web.config file:
<pages>
<namespaces>
<add namespace="System.Web.Optimization"/>
</namespaces>
<tagMapping>
<add tagType="System.Web.UI.HtmlControls.HtmlForm" mappedTagType="we3.Site.Form" />
</tagMapping>
<controls>
<add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt"/>
</controls>
</pages>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
Install it from nugget: https://www.nuget.org/packages/Microsoft.AspNet.Web.Optimization.WebForms/
Install-Package Microsoft.AspNet.Web.Optimization.WebForms
Or you can manually download it from: https://www.nuget.org/api/v2/package/Microsoft.AspNet.Web.Optimization.WebForms/1.1.3
and add it as reference to your project (unzip first the .nupkg file)
Installing the package Microsoft.AspNet.Web.Optimization is what resolved this for me.
Install-Package Microsoft.AspNet.Web.Optimization
I use Visual studio 2013 (Windows) to build a small .NET 4.5 application using Npgsql and Entity Framework 6.
On windows it just works fine.
But on Raspbian, the app crash saying it cannot find npgsql provider.
Unhandled Exception:
System.Configuration.ConfigurationErrorsException: Failed to find or load the registered .Net Framework Data Provider 'Npgsql'.
at System.Data.Common.DbProviderFactories.GetFactory (System.String providerInvariantName) [0x00000] in <filename unknown>:0
[...]
On my raspberry pi 2.
I have manually installed Mono v4.0.2
I have copied my app including:
npgsql.dll v2.2.5.0
npgsql.entityframework same version
mono.security v4.0.2
and my app.config contains :
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<providers>
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql.EntityFramework" />
</providers>
</entityFramework>
<connectionStrings>
<add name="minitestEntities" connectionString="metadata=res://*/Model2.csdl|res://*/Model2.ssdl|res://*/Model2.msl;provider=Npgsql;provider connection string="PORT=5432;TIMEOUT=15;POOLING=True;MINPOOLSIZE=1;MAXPOOLSIZE=20;COMMANDTIMEOUT=20;COMPATIBLE=2.2.5.0;DATABASE=minitest;HOST=10.0.0.1;INTEGRATED SECURITY=True;PASSWORD=azerty;USER ID=theuser"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
So i'm wondering if npgsql librairies are correctly loaded, or a if a reference is missing.
I found no docs on how to use npgsql on recent mono + ARM environment.
Any info about this would be really appreciated.
ok i found the solution in an other discution. In the meanwhile i forgot to note its URL so here the answer :
We have to add manually the provider description into app.config :
<system.data>
<DbProviderFactories>
<add name="Npgsql Data Provider"
invariant="Npgsql"
support="FF"
description=".Net Framework Data Provider for Postgresql Server"
type="Npgsql.NpgsqlFactory, Npgsql, Version=2.2.5.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" />
</DbProviderFactories>
</system.data>
The version and PuclicKeyToken MUST match with npgsql.dll.
To get the public key token, you can run that code :
typeof(Npgsql.NpgsqlFactory).AssemblyQualifiedName
Now i have no idea why this step is not necessary into windows, but a have to do into linux...
As part of plans to migrate an existing website from .NET 4 to .NET 4.5.1 we have learned that we will need to move from using Enterprise Library 5 to version 6.
We're using the caching block in version 5, but this has been removed from version 6, so we plan (as recommended) to refactor our code to use System.Runtime.Caching instead.
We would like to ensure that the settings (in Web.config) we will for System.Runtime.Caching will give us the same (or similar...) behaviour as those we currently use for the Enterprise Library 5 caching block.
The Enterprise Library 5 caching block settings we are currently using are:
<configSections>
<section name="cachingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerSettings, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>
<cachingConfiguration defaultCacheManager="Cache Manager">
<cacheManagers>
<add name="Cache Manager"
type="Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
expirationPollFrequencyInSeconds="60"
maximumElementsInCacheBeforeScavenging="1000"
numberToRemoveWhenScavenging="10"
backingStoreName="NullBackingStore" />
</cacheManagers>
<backingStores>
<add type="Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.NullBackingStore, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="NullBackingStore" />
</backingStores>
</cachingConfiguration>
The System.Runtime.Caching settings we are planning to use are:
<system.runtime.caching>
<memoryCache>
<namedCaches>
<add name="default"
cacheMemoryLimitMegabytes="10"
physicalMemoryLimitPercentage="0"
pollingInterval="00:01:00" />
</namedCaches>
</memoryCache>
</system.runtime.caching>
Are we on the right track here?
Note that we do not have comprehensive load testing facilities for our website, so are not able to satisfactorily test our use of caching before we release the website.
I am developing WCF service hosted by IIS. I need to add KnownType attribute to my base class. One way of adding KnownType attribute is to add a section into the Web.config file like this:
<system.runtime.serialization>
<dataContractSerializer>
<declaredTypes>
<add type="MyBase, MyBaseDll">
<knownType type="MyDerived, MyDerivedDll"/>
</add>
</declaredTypes>
</dataContractSerializer>
</system.runtime.serialization>
But I got error message when my mouse is over the MyBase. The Error message is “Invalid Module Qualification: Failed to resolving assembly MyBaseDll”. Same error message for MyDerivedDll.
Additional information:
Both MyBaseDLL.dll and MyDerivedDLL.dll are in the IIS /bin folder. Both DLLs reference no other assembly other than .net system assemblies
Have you tried giving the full name of the assemblies and full name of the types (namespaces and all) ...
<add type="MyNamespace.MyBase,
MyBaseDLL, Version=v.v.v.v, Culture=neutral,
PublicKeyToken=XXXXXX">
<knownType type="MyNamespace.MyDerived,
MyDerivedDLL, Version=v.v.v.v, Culture=neutral,
PublicKeyToken=XXXXXX"/>
</add>
What happens when you run the service? The error message could be bogus. For instance, ReSharper sometimes gets confused about assembly references in config files.
OTOH, other times, it's correct.