I want to create a web service,the theme this service is it has two take parameters as two audio files and generate a text file as output file.
How would I host this service in server and call this service with server url name?
Ex:

If I call the url like above from an application I have to get the output as a text file.
That is to be stored in my local machine.
Please help me in this

Dani AI

Generated

— practical approach: expose a POST REST endpoint that accepts two uploaded files (multipart/form-data), runs your audio-to-text processing, and returns the transcription as a downloadable text file (or returns a job id if processing is long-running). The client must send file bytes (not just local filenames). For simple synchronous workflows you can return the result straight away; for heavy/slow work accept files, queue a job, and give the client a URL or job id to fetch the result later.

Example (ASP.NET Web API 2): this action reads multipart content, gets two files, calls a processing function, and returns a text file as an attachment.

[HttpPost]
[Route("api/getOutput")]
public async Task<HttpResponseMessage> Post()
{
    if (!Request.Content.IsMimeMultipartContent())
        return Request.CreateResponse(HttpStatusCode.UnsupportedMediaType);

    var provider = await Request.Content.ReadAsMultipartAsync(new MultipartMemoryStreamProvider());
    var files = provider.Contents.Where(c => c.Headers.ContentDisposition.FileName != null).ToList();
    if (files.Count < 2)
        return Request.CreateResponse(HttpStatusCode.BadRequest, "Two files required.");

    var bytes1 = await files[0].ReadAsByteArrayAsync();
    var bytes2 = await files[1].ReadAsByteArrayAsync();

    string resultText = ProcessAudioAndReturnText(bytes1, bytes2); // implement this

    var resp = Request.CreateResponse(HttpStatusCode.OK);
    resp.Content = new StringContent(resultText, Encoding.UTF8, "text/plain");
    resp.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
    { FileName = "output.txt" };
    return resp;
}

Client test (curl):

curl -X POST -F "file1=@audio1.wav" -F "file2=@audio2.wav" http://yourserver:8080/api/getOutput -o output.txt

Troubleshooting and tips: increase IIS/request limits for big files (maxRequestLength, requestFiltering), avoid loading very large files fully into memory (stream to disk or use streaming APIs), validate MIME/type and sanitize inputs, enable HTTPS and authentication, and consider async job queues for long transcriptions. As noted, do not send client-side filenames only; and was right that Web API is a natural fit for this pattern.

Recommended Answers

All 2 Replies

If I understand your question, you want to send your local file names to server and then server read them and calculate the response.
When you send your request to server (HTTP-GET), the server is not able to read your local files. You need to send files binary data to server instead of their name. Or you need to put all your binary data to server web service application folder.

This is a pretty vague question, but here are some thoughts to help you get on the right track.

The Service:
This project would be web application with Webapi. You would create a Webapi controller. Once you create one, it has the main template with different methods which you can call. It gives you different GET and POST methods so you can see how they need to be set up. As stated by another user, you can not directly post a wav file. You can pass the files in a "multi-part form" though. This will allow you to stream in the content of the files and manipulate them through the service.

Hosting the service:
As for hosting, you can do this a number of ways. You can either create this as a service using something like OWIN, or you could host this as a web application by publishing the application to a, IIS (Internet Information Services) web server. If you want to run it locally on your machine, you just need to install IIS on your local machine. It is pretty simple to do and there are many great tutorials out there on how to do this if you need more help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.