Мы пытаемся POST к методу REST WCF. Мы можем успешно выполнить POST с использованием SoapUI, Postman и YARC, но когда мы попробуем в Angular 5, я получу объект NULL.
Код клиента:
const headers: any = {'Content-Type': 'application/json'};
return this.ajax.request<any>({
url: url,
method: method (POST),
headers: headers,
options: {
body: JSON.stringify(req.body)
}
});
}
public request<T>(req: AjaxRequest): Observable<HttpEvent> {
return this.http.request<T>(req.method, req.url, req.options)
}
//this.http = HttpClient
// Component
public onNext(event: any): void {
this._saveInfo(getInsertDmgReqPayload({
data: event.value,
dmgInfo: this.responses['dmg'],
emailId: this.util.getQueryStringValue('uname')
}));
this.util.navigate('education');
}
private _saveInfo(data: any): void {
this.appraisal.request('saveDmgInfo', null, {body: data})
.subscribe(v => {
console.log(v);
});
}
Логика на стороне сервера:
// WCF Interface definition
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
Result InsertDemographicInfo(Demographic d);
// Service code
public Result InsertDemographicInfo(Demographic d) // The Demographic object is null when posting from Angular
{
Result result = new Result();
try
{
DemographicFactory.InsertDemographicInfo(d);
result.Status = "Success";
}
catch (Exception ex)
{
result.Status = "Fail";
result.Message = ex.Message;
}
return result;
}
Я попытался назвать параметр в Angular, как упоминалось здесь и здесь , и параметр всегда равен нулю. Пожалуйста помоги? У меня достаточно седых волос.