简体   繁体   English

Angular2调用WCF服务失败

[英]Angular2 call WCF service fails

Below angular code which calls the WCF service. 下面的角度代码调用WCF服务。

public customLogin(user: string, pass: string): Observable<string> {
    let headers = new Headers({ 'Content-Type': 'application/json' });
    let options = new RequestOptions({ method: "POST",headers: headers,body: user} );

    return this.http.post(this.url, user, options)
        .map(this.extractData)
        .catch(this.handleError);
}

WCF service url in local 本地的WCF服务网址

' http://localhost:34244/CitizenService.svc/register '; ' http:// localhost:34244 / CitizenService.svc / register ';

It fails with 405 error. 它失败并显示405错误。

在此处输入图片说明

Anyone knows what could be the issue? 有人知道这可能是什么问题吗?

You're having a CORS issue here. 您在这里遇到CORS问题。 The request you're showing is actually a pre-flight OPTIONS request (not yet the actual POST request)and the 405 - Method not allowed indicates that WCF doesn't allow the OPTIONS method. 您显示的请求实际上是飞行前OPTIONS请求(尚未实际的POST请求),并且405-不允许使用方法表示WCF不允许使用OPTIONS方法。

Maybe this is also helpful: How to add cross domain support to WCF service 也许这也有帮助: 如何为WCF服务添加跨域支持

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM