Call backend .NET dll from ASP.NET Web api - c#

I building client server app.
The business logic is build in C++ /CLI.
In the same solution I have ASP.NET Web api project.
For logon i have method in backend. For logon i need to do this
using Back_End;
public IHttpActionResult Logon([FromBody]Logon_Request model)
{
string Answer = Back_End.Logon(model.Name, model.Password);
}
Back_End is inside of the dll in the same solution.
When I try to call api/logon it retunes me an exception.
{
"Message": "An error has occurred.",
"ExceptionMessage": "Could not load file or assembly 'Back_End, Version=1.0.5676.23091, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Attempt to load an unverifiable executable with fixups (IAT with more than 2 sections or a TLS section.) (Exception from HRESULT: 0x80131019)",
"ExceptionType": "System.IO.FileLoadException",
"StackTrace": ".........."
}
Of course, because it is not on IIS server.
Finally my questions:
-But do I need to deploy all my business logic dll on server?
-Will whey work here?
-Is any "better" way to do what I want?
-Maybe I need to sun it as a service and make calls? But it will be API for API.

Web.Config File
<compilation debug="true" targetFramework="yourTargetFramework">
<assemblies>
<add assembly="yourAssemblyName, Version=yourAssemblyVersion, Culture=neutral, PublicKeyToken=yourPublicKeyToken" />
</assemblies>
</compilation>
login.aspx page
<%# Register Assembly="yourAssemblyName, Version=yourAssemblyVersion, Culture=neutral, PublicKeyToken=yourPublicKeyToken" Namespace=".dll Namespace" TagPrefix="name to call the loginUserControl" %>
Ex.
...TagPrefix="rs" %>
<rs:Login/>

Related

Could not load file or assembly 'Microsoft.Web.Iis.Rewrite.Providers, Version=7.1.761.0, Culture=neutral, PublicKeyToken=0545b0627da60a5f'

I have setup ASP project but when I am opening my local url in browser I am getting below error:
Parser Error Message: Could not load file or assembly
'Microsoft.Web.Iis.Rewrite.Providers, Version=7.1.761.0,
Culture=neutral, PublicKeyToken=0545b0627da60a5f' or one of its
dependencies. The system cannot find the file specified.
Line 16: <compilation debug="true" targetFramework="4.6.2" defaultLanguage="c#">
Line 17: <assemblies>
Line 18: <add assembly="Microsoft.Web.Iis.Rewrite.Providers, Version=7.1.761.0, Culture=neutral, PublicKeyToken=0545B0627DA60A5F" />
Line 19: </assemblies>
Line 20: </compilation>
Had the same problem using a DB provider. Fixed it by installing the URL Rewrite extensibility code samples.
During the installation make sure to select the "Runtime" option in the custom setup. This will register the sample providers in .NET Global Assembly Cache so that they can be used by URL Rewrite Module.
Using Custom Rewrite Providers with URL Rewrite Module
You error message indicates that the DLL is missing. Have you installed the IIS URL Rewrite Module?
For more another possible solution you can look at this post.

Double error in Web.config file ASP.NET MVC

So when I publish my application I these following errors which I do not get in local mode.
"System.Security.SecurityException: Request for the permission of type
'System.Security.Permissions.SecurityPermission, mscorlib,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
failed."
So it is said that I'm supposed to write the following code in my Web.config to solve this first error:
<trustLevel name="Full">
So I did, but then, I got this error:
"This configuration section cannot be used at this path. This happens
when the site administrator has locked access to this section using
from an inherited configuration file."
It apparently has to do with the machine.config (which I cannot find)...
Does anyone have a proper solution for this?
If you wish to test it yourselves, here is the URL:
http://wideart.se/Exhibition
Regards
What is around <trustLevel name="Full"> ?
Is it inside system.web?
Try
<securityPolicy>
<trustLevel name="Full" policyFile="internal"/>
</securityPolicy>

Two errors in Web.config ASP.NET MVC

so firstly, I get this error when publishing my web application:
"System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."
So it is said that I'm supposed to write the following code in my Web.config:
<trustLevel name="Full">
So I did, but then, I got this error:
"This configuration section cannot be used at this path. This happens when the site administrator has locked access to this section using from an inherited configuration file."
At it has to apparently have to do with the machine.config (which I cannot find)...
Does anyone have a proper solution for this?
Regards,

Consuming RIA services without a silverlight project

We have a silverlight project that uses RIA services. There is some code that I want to share between that project and a web service. I have to leave the code where it is now, i.e. I cannot share the code.
What I thought would be good is for the web service to call the RIA service. It will be sitting on the same server.
I went to my web service project, and added a service reference to the ria service. I clicked advanced and ticked the option for it to 'generate asynchronous operations'.
I thought it would be all good to go, but I got some warnings. The client code that it generated was missing any actual code relating to the asynchronous calls, and the app.config is also empty. Here are the warnings,
Warning 2 Custom tool warning: Cannot import wsdl:binding
Detail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on.
XPath to wsdl:portType: //wsdl:definitions[#targetNamespace='http://tempuri.org/']/wsdl:portType[#name='CarServiceSoap']
XPath to Error Source: //wsdl:definitions[#targetNamespace='http://tempuri.org/']/wsdl:binding[#name='BasicHttpBinding_CarServiceSoap'] C:\Develop\DotNet\Trunk\Applications\WcfServices\CarTransmitter\CarTransmitter.Core\Service References\CarService\Reference.svcmap 1 1 CarTransmitter.Core
Warning 3 Custom tool warning: Cannot import wsdl:port
Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.
XPath to wsdl:binding: //wsdl:definitions[#targetNamespace='http://tempuri.org/']/wsdl:binding[#name='BasicHttpBinding_CarServiceSoap']
XPath to Error Source: //wsdl:definitions[#targetNamespace='http://tempuri.org/']/wsdl:service[#name='CarService']/wsdl:port[#name='BasicHttpBinding_CarServiceSoap'] C:\Develop\DotNet\Trunk\Applications\WcfServices\CarTransmitter\CarTransmitter.Core\Service References\CarService\Reference.svcmap 1 1 CarTransmitter.Core
Warning 1 Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: Referenced type 'CarData.Organisation, CarData, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' with data contract name 'Organisation' in namespace 'http://schemas.datacontract.org/2004/07/CarData' cannot be used since it does not match imported DataContract. Need to exclude this type from referenced types.
XPath to Error Source: //wsdl:definitions[#targetNamespace='http://tempuri.org/']/wsdl:portType[#name='CarServiceSoap'] C:\Develop\DotNet\Trunk\Applications\WcfServices\CarTransmitter\CarTransmitter.Core\Service References\CarService\Reference.svcmap 1 1 CarTransmitter.Core
Use the RIA services project option to create your service library. That creates 2 projects that are bound together (for code gen of the proxy objects). Both are effectively just libs (1 Silverlight and 1 .Net)
Link any RIA services client library to you Silverlight app. Then link the .web RIA project to your hosting web app (for the standard RIA use). You can also add the .web library to your Wcf service as a .Net lib (not consume it as a service).
If you did not create your main Silverlight project as a RIA services project you will need to move the settings across from the app.config file to your web.config file. If you already have the service support settings you only need to copy the db connection string across. The db connection string only should be needed for you Wcf project.
You should then be able to either use the server-side RIA calls (don't forget to add your own submitchanges calls as RIA does that behind the scenes once per batch of updates), or just use the data layer (EF etc) directly.
Not finished completely, got quite a bit further along. The problems I am having now warrant a new question.
The solution to the above problem is to untick the option 'reuse types in referenced assemblies'. When you add service reference, you click the advanced button and you get the option 'reuse types in referenced assemblies'.
This is because I am sharing some code between the two projects I am using, and it was trying to 'reuse' objects I had on my side in the shared code. Instead I just wanted it to create proxy objects for me and not reuse those objects.
Yes. It is possible to do.
Create a library project
Add LINQ to Entity model
Add public class DomainService1 : LinqToEntitiesDomainService
Check if your web.config looks like this one
[?xml version="1.0"?]
[configuration]
[configSections]
[sectionGroup name="system.serviceModel"]
[section name="domainServices" type="System.ServiceModel.DomainServices.Hosting.DomainServicesSection, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" allowDefinition="MachineToApplication" requirePermission="false" /]
[/sectionGroup]
[/configSections]
[system.webServer]
[validation validateIntegratedModeConfiguration="false" /]
[modules runAllManagedModulesForAllRequests="true"]
[add name="DomainServiceModule" preCondition="managedHandler" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /]
[/modules]
[/system.webServer]
[system.serviceModel]
[domainServices]
[endpoints]
[add name="OData" type="System.ServiceModel.DomainServices.Hosting.ODataEndpointFactory, System.ServiceModel.DomainServices.Hosting.OData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /]
[add name="soap" type="Microsoft.ServiceModel.DomainServices.Hosting.SoapXmlEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /]
[add name="JSON" type="Microsoft.ServiceModel.DomainServices.Hosting.JsonEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /]
[/endpoints]
[/domainServices]
[serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /]
[/system.serviceModel]
[connectionStrings]
[add name="ASPNETDBEntities1" connectionString="metadata=res:///Model1.csdl|res:///Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=localhost;initial catalog=ASPNETDB;persist security info=True;user id=sa;password=yourpassword;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /][/connectionStrings]
[system.web]
[compilation debug="true"][assemblies][add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /][/assemblies][/compilation]
[/system.web]
[/configuration]
Do WEB Publishing locally and test service link.
Enjoy!

Error in webservice after publishing

I created a webservice when it hosted on my local computer it works fine, but when i publish it to the web host, it doesnt work any more, i guess its a question about how the webserver is configured, but can i make some changes in web.config so it will work?
The error i get is below:
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: Could not load file or assembly 'MySql.Data, Version=5.0.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The system cannot find the file specified.
Source Error:
Line 37:
Line 38:
Line 39:
Line 40:
Line 41:
Source File: c:\webs\talkactive\gb1634\qaz.dk\web.config Line: 39
Assembly Load Trace: The following information can be helpful to determine why the assembly 'MySql.Data, Version=5.0.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' could not be loaded.
The webservice uses a c# class placed in the app_code folder. That c# class uses mysql.
When i use the class in a normal .aspx file it works fine
I guess the obvious thing would be to check whether the MySql.Data exist in the GAC (or the web service's bin folder) on the server and is of the correct version and public key?
Basically, you are missing this DLL. You should look at putting it in the bin directory of your webservice.
There could also be a versioning conflict between the MySql client you want and what is installed on the server. You can add the following section to your web.config file and specify the proper version/public key you need:
<compilation debug="false">
<assemblies>
<add assembly="MySql.Data, Version=5.0.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
</assemblies>
</compilation>

Categories