I am trying to take the code in an .ASMX web service and change it into a class library project. The web service project has a web.config file with:
<applicationSettings>
<myService.Properties.Settings>
<setting name="DownloadChunkSize" serializeAs="String">
<value>100000</value>
</setting>
..and the code in the FileService.asmx.cs file uses this to retrieve the value:
int chunkSize = (int)Properties.Settings.Default.DownloadChunkSize;
When I try to re-architect this code to eliminate the .asmx web service, I get a compile time error in my class library project because there is no longer a web.config available. Let me try to explain a bit more about what I’ve done so far (and why):
The motivation for this is to simplify my projects. That is, I have a Vstudio solution with an .asmx project that works. It has a few methods and encapsulates the communication with another .asmx web service supplied by a vendor.
The new design I am attempting is as follows:
Project 1 is a class library project called ProxyASMX with a web reference to the vendor web service. I’ve provided no code here; it simply has a small app.config pointing at the vendor web service.
Project 2 is a class library project with a reference to the ProxyASMX.dll. The code in this FileService.cs file is the same as my original web service but the [webmethod] attributes have been removed. This is the project I’m having trouble compiling.
Project 3 is a web application project with 2 HTTPHandlers – Upload.ashx and Download.ashx. This project will have a reference to the Project 2 class library. I tried replacing the small default web.config content with the more comprehensive web.config content from the original solution but when that did not work I thought I better consult the experts about this venture.
I hope the above sketch is clear. I THINK this should be very do-able but now I am not so sure.
You can add Application Settings to a class library. So you add the Application Settings on the project that “consumes them”. Then you simply copy these config sections “up the project stack”.
So if I understand you correct, you need to add the DownloadChunkSize setting to Project 2 and copy this section to your web.config in Project 3. This will be something like:
You can access this setting inside Project 3 using:
And in Project 2: