1
我正在嘗試我的第一個Angular 2應用程序。目前,我正面臨Web服務調用的問題。我有像www.myserver.domain/folder/api/webservice.asmx/method
這樣的網址的網絡服務。從角度調用asmx webservice 2
當我嘗試使用Firefox調用它時,顯示該方法,如果我在localhost上運行它,我可以正確測試它。但是如果我嘗試從角碼中調用它,它會失敗。有人可以告訴我,我做錯了什麼?
我的代碼:
@Injectable()
export class MyService {
// URL to web api
private serviceUrl = 'http://www.myserver.domain/folder/api/webservice.asmx/method';
constructor(private http: Http) { }
getData() {
let body = JSON.stringify({ Param1: "0", Param2: "0", Param3: "0" });
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this.http.post(this.serviceUrl, body, options)
.toPromise()
.then(response => response.json().data as MyDataClass[])
.catch(this.handleError);
}
handleError(error: any) {
console.error('An error occurred', error);
return Promise.reject(error.message || error);
}
}
對於referrence,這裏是我的web服務看起來像:
[WebService(Namespace = "mynamespace")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[ScriptService]
public class webservice: System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void List(int Param1 = 0, int Param2 = 0, int Param3 = 0)
{
//... some code to populate result of type List<Dictionary<string, string>>
data.Message = Common.TranslateToSerialize(result);
Context.Response.Write(js.Serialize(data.Message));
return;
}
謝謝你提供的任何幫助。請考慮我是JS/Ang2的新手,所以在提問時請儘可能詳細:)
嗨我試過在angular2中使用asmx webservice,但沒有獲得解決方案你有任何演示參考? – Pravin