Why and what are the differences between these two text files? - asmx

We were like migrating and old application to a new architecture. The two files shown in notepad are DAT files. The first file was created by the old application. The second one was created by the "new implementation".
A little history behind the new implementation: These applications (in the "new implementation") are supposed to be hosted in a web farm environment. There was a specific application called the payroll - this is the application responsible for the creation to the files shown below. I had used visual studio's pre-processed text templates to generate the DAT files. At the time there was no web service involved. But later we decided that the creation of such files needs to be centralized.
So we exposed a web service to do this.
Essentially there was no change in logic. I still used the pre-processed templates. But the output of this template was transmitted over the web to the web service. After which the files started appearing like as shown in the 2nd image.
There was no problem before the centralization. So what has happened here? How can I make the DAT file (in the new implementation) look the same as in the old?

One probably uses CR LF = \r\n
The other probably just uses LF = \n
CR short for Carriage Return.
LF short for Line Feed.

This looks like a a carriage return issue. I guess the web service use a UNIX server with Unix style line feeds, and the other file comes from a windows?
In that case, you'll just have to change endlines into CRLF.
Unix systems use LF (0x0A), when Windows system require CR (0x0D) followed with LF (0x0A), so simply replace LF with CRLF, if it is your issue.

Related

Creating a "web service" using ASP.net - what's in the DLL?

All,
Sorry in advance - I'm a total novice when it comes to ASP.net.
I'm working on a project that's fairly simple. I have single HTML page that collects input from the user. When the input is complete - the html page uses AJAX to post the data to a web service. That service receives the data, does some processing on it, then sends back a response.
The "client" part of this app is pure HTML/Javascript (not ASP.net), and is complete and works perfectly.
The "service" part of this app (MyHandler.ashx) is built using ASP.net. Technically - what it does is receive data from the AJAX post. It then uses Microsoft.Office.Interop.Excel to open an Excel spreadsheet, pass the users' inputs into that spreadsheet, then retrieve several calculated values from the spreadsheet, and returns those values in the response to the AJAX post.
Using Visual Studio VS I've got this whole process running locally on my PC.
When I "publish" the project - VS creates a ton of files. I sent those files to the team that manages the server; they deployed them, and voilĂ  - it works. (The necessary Office interop libraries are installed on the server).
So - my question - as I make a few modest changes (e.g., validation, error handling) to the handler - MyHandler.ashx - which of those published files actually change? If i want to reploy - do I simply need to resend an updated version of MyHandler.ashx? Or, do simple coding changes to that file require changes to the DLL?
I guess my question is, generally - what's in the DLL? (E.g., is it a compiled version of MyHandler.ashx?)
More specifically - publishing my project creates the following files that I don't really understand:
Web.config
Global.asax (in my project, there's not much in here)
bin/MyProject.dll
So, if I make changes to MyHandler.ashx - can I simply reploy THAT file? Or, do I need to "publish", then "redeploy" thd dll? (By changes - I mean simple code changes, not decisions to include/exclude other external dependencies).
Sorry - this question must seem like nonsense to knowledgeable ASP.net developers. But, with other technologies I've used, things were clear:
If you're developing a Flash project, you write source code in .FLA files, then compile, then deploy the resulting .SWF files.
If you're developing an HTML/JavaScript/PHP project, you write those files, then deploy those same files
I'd trying to get a better understanding of what's what with ASP.net.
Thanks again.
The DLL contains the compiled code behind the ASHX file. The ASHX is just a service definition for an HTTP handler. When you make changes to the service (e.g. the code), simply issue another Publish like you did before and send the entire package.
But in short, when you change the code, the DLL is what's changing.

ASP .NET WebService that accept large file input from a different server

I need to build a Web Service in ASP .NET 3.5 (C#) that accepts a large file (documents like DOC/PDF/XLS and similar of about 10-20 MB) as input parameter.
This Web Service is called by many 3rd party applications, many of which are developed in PHP. Once the WS has the file, it has to put it inside another .NET application documents archive.
I already tested the entire round and it works. The file wasn't passed inside the call url, it was taken by a server local path.
Now, my problem is: how can I pass a big file to the WS, when the calls come from an application that is hosted on a different server?
EDIT: added an example.
The case:
Server A is a PHP application that calls the .NET Web Service on Server B and passes it a file. Then, the WS on Server B will post the file somewhere else on Server C.
In other words my problem is the communication between Server A and Server B. I need something like a "query string" which I can use to pass a file as byte array or anything else. Something like:
http://www.myserver.com/InsertFile.ashx?file=A3Fdf3Gjy5... <-- byte array of the file
Obviously, the query string doesn't suit very well to my purpose...
I want to know if what I want to do is possible and which technic I should use to make it works.
You could use a POST instead of a GET to allow larger files (and be semantically correct). A similar question is asked here. Leading to this link
If the web service is yours you can achieve it by changing web.config file. Please refer :
How do I upload large (> 25MB) files to a web service?

localization fails with strongly typed resources in web application

We've created two Resource files GlobalResources.resx (English) and GlobalResources.de.resx (German).
This works (text is translated to language based on web browser setting):
string s = HttpContext.GetGlobalResourceObject("GlobalResources",
"YouHaveSuccessfullyLoggedOut");
This does not (text is always English):
string s = Resources.GlobalResources.YouHaveSuccessfullyLoggedOut;
Why?
It's now working again.
We think it may have happened because the application was running (in Debug), or the .resx file was open (in an VS Editor window) when we re-factored the string into a resource (using http://resourcerefactor2010.codeplex.com/). It's to do with when VS decides to generate the .designer files (we've even seen it create two .designer files for one .resx file) - this whole area is flaky in VS2010 and needs be treated gently!

Editable resource files in a deployed ASP.Net site

Apparently, my understanding of .resx files was flawed - I had assumed (without testing) that they were deployed as XML so as to remain editable at a later time - clearly, this is incorrect. So, I'm left with a gap I need to fill for the labels and format strings in our company's web application, hopefully someone here can point me in the right direction.
I'm looking for a solution that can support multiple languages, and can be edited by a system administrator at a later date. For the first requirement, resx files work perfectly - if the UI culture is changed, the appropriate resource is used, or it defaults to the top level resource if no culture specific resource is available. Unfortunately, if company A wants a resource string to be "Account Number", and company B wants that same string to be "Account ID", we have no good way to support this - we don't want to have to compile a different version of the web site for each company, just to change a few resource strings - ideally, those strings could simply be set by the company's tech person after deployment.
Is there a framework out there that will be of use here? Or perhaps a different way to approach the problem using resx files?'
You really can't use resx files for your pre-compiled solution.
There are two options:
Deploy an uncompiled version of your site.
Implement a database solution, and create an administrative area for updating the text, so a user may log in and make changes. You would be able to maintain your precompiled code.

web.config - auto generate a release version

Simple task, but for some reason no simple solution just yet.
We've all got web.config files - and I haven't worked anywhere yet that doesn't have the problem where someone yells across the room "Sh*t, I've just uploaded the wrong web.config file".
Is there a simple way of being able to auto generate a web.config file that will contain the right things for copying to release? An example of these being:
Swap connection string over to use live database
Change
Switch over to use the live/release logging system, and live/release security settings
(in our case we need to change the SessionState mode to InProc from StateServer - this isn't normal)
If you have others, let me know and I'll update it here so it's easy for someone else to find
Maintaining 2 config files works, but is a royal pain, and is usually the reason something's gone wrong while you're pushing things live.
Visual Studio 2010 supports something like this. Check it out here.
How are you deploying your builds. In my environment, this used to be a pain point too, but now we use cruisecontrol.net and script our builds in nant. In our script, we detect the environment and have different versions of the config settings for each environment. See: http://www.mattwrock.com/post/2009/10/22/The-Perfect-Build-Part-3-Continuous-Integration-with-CruiseControlnet-and-NANT-for-Visual-Studio-Projects.aspx for my blogpost onthe subject of using cruisecontrol.net for build management. Skip to the end fora brief description of how we handle config versions.
In my most recent project I wrote a PowerShell script which loaded the web.config file, modified the necessary XML elements, and saved the file back out again. A bit like this:
param($mode, $src)
$ErrorActionPreference = "stop"
$config = [xml](Get-Content $src)
if ($mode -eq "Production")
{
$config.SelectSingleNode("/configuration/system.web/compilation").SetAttribute("debug", "false")
$config.SelectSingleNode("/configuration/system.web/customErrors").SetAttribute("mode", "off")
$config.SelectSingleNode("/configuration/system.net/mailSettings/smtp/network").SetAttribute("host", "live.mail.server")
$config.SelectSingleNode("/configuration/connectionStrings/add[#name='myConnectionString']").SetAttribute("connectionString", "Server=SQL; Database=Live")
}
elseif ($mode -eq "Testing")
{
# etc.
}
$config.Save($src)
This script overwrites the input file with the modifications, but it should be easy to modify it to save to a different file if needed. I have a build script that uses web deployment projects to build the web app, outputting the binaries minus the source code to a different folder - then the build script runs this script to rewrite web.config. The result is a folder containing all the files ready to be placed on the production server.
XSLT can be used to produce parameterized xml files. Web.config being xml file this approach works.
You can have one .xslt file(having xpath expressions).
Then there can be different xml files like
1. debug.config.xml
2. staging.config.xml
3. release.config.xml
Then in the postbuild event or using some msbuild tasks the xslt can be combined with appropriate xml files to having different web.config.
Sample debug.config.xml file can be
<Application.config>
<DatabaseServer></DatabaseServerName>
<ServiceIP></ServiceIP>
</Application.config>
.xslt can have xpaths referring to the xml given above.
Can have a look at the XSLT transformation This code can be used in some MSBuild tasks or nant tasks and different web.config's can be produced depending on the input config xml files.
This way you just have to manage the xml files.
There is only one overhead that the xslt file which is similar to web.config need to be managed. i.e whenever there is any tag getting added in the web.config the xslt also needs to be changed.
I don't think you can 100% avoid this.
The last years of work ever and ever shows: where human worked, there are fails.
So, here are 3 ideas from my last company, not the best maybe, but better then nothing:
Write an batch file or an C#.Net Application that change your web.config on a doubleclick
Write a "ToDo on Release"-List
Do pair-realesing (== pair programming while realease :))

Resources