0

I am trying to call my asp.net web api endpoint from my angular 7 application by passing a string value and getting 404 not found error. If you see below i am calling the getDocumentUploadDetailsByIds and passing the string to it. I am converting integer array to string and sending it

This is how the url looks: http://localhost:56888/api/documentupload/detailsByIds/591006,591007

Component


public createDocument() {
    const documents: IDocumentDetails[] = this.files.map(doc => {
        return { // notice just a curly bracket, and in the same line with 'return'
            file: doc.fileDropEntry.fileEntry,
            documentTypeId: doc.selectedDocumentItem.Id,
            name: doc.name,
            documentDate: doc.selectedDate
        };
    });
    this.documents = { managerStrategyId: 0, documentDetails: null };
    this.documents.managerStrategyId = this.ManagerStrategyId;
    this.documents.documentDetails = documents;

    this.documentUploadService.createDocumentUpload(this.documents)
        .then((result) => {
            if (result) {
                this.documentIds.ids = Object.keys(result).map(k => result[k]);
                this.getDocumentUploadDetailsByIds(this.documentIds.ids.toString());
                this.setGridOptions();
                this.setColumns();
                this.notify.success('Documents uploaded Successfully');
            }
        }).catch(err => {
            this.notify.error('An Error Has Occured While uploading the documents');
        });
}


public getDocumentUploadDetailsByIds(documentIds) {
    if (this.ManagerStrategyId != null) {
        this.Loading = true;

        this.initGrid();
        this.documentUploadService.getDocumentUploadDetailsByIds(documentIds)
        .subscribe(data => {
            this.DocumentUploadDetails = data;
            this.Loading = false;

        },
            err => {
                this.Error = 'An error has occurred. Please contact BSG';
            },
            () => {
            });
    }
}

Service component

getDocumentUploadDetailsByIds(documentIds: string) {
    return this.mgr360CommonService.httpGet('/api/documentupload/detailsByIds/' +  documentIds );
}     

httpGet(url: string): Observable<any> {
    return this.httpClient.get( this.webApiLocation + url, httpPostOptions)
        .pipe(map((response: Response) => {
            return response;
        }), catchError(error => {
            this.onError(error);
            return Promise.reject(error);
        }));
} 

Server side

[HttpGet]
[SkipTokenAuthorization]
public IHttpActionResult DetailsByIds(string documentIds)
{
    var viewModel = GetDocumentUploadDetailsByIds(documentIds);
    return Ok(viewModel);
}
1
  • How did you configure the route table in your ASP.NET project? (search .MapHttpRoute in your project) Commented Jul 8, 2019 at 13:37

1 Answer 1

1

Try this:

[HttpGet, Route("DetailsByIds")]
public IHttpActionResult DetailsByIds(string documentIds)
{
     var viewModel = GetDocumentUploadDetailsByIds(documentIds);
     return Ok(viewModel);
}

Construct your call in the following way:

http://localhost:56888/api/documentupload/detailsByIds?documentIds=591006,591007

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.