Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 405方法不允许Wcf服务和Ionic_C#_Wcf_Cors - Fatal编程技术网

C# 405方法不允许Wcf服务和Ionic

C# 405方法不允许Wcf服务和Ionic,c#,wcf,cors,C#,Wcf,Cors,我正在使用wcf rest api与ionic应用程序通信。在使用RESTAPI时,控制台引发错误“405方法不允许”。通过搜索谷歌发现一定有一个“CORS错误” 通过在Global.asax文件中添加以下行重新配置Wcf服务 protected void Application_BeginRequest(object sender, EventArgs e) { HttpContext.Current.Response.AddHeader("Acces

我正在使用wcf rest api与ionic应用程序通信。在使用RESTAPI时,控制台引发错误“405方法不允许”。通过搜索谷歌发现一定有一个“CORS错误”

通过在Global.asax文件中添加以下行重新配置Wcf服务

protected void Application_BeginRequest(object sender, EventArgs e)
        {

            HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
            if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
            {
                HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache");
                HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST");
                HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
                HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
                HttpContext.Current.Response.End();
            }


        }
然后我得到了

the 'access-control-allow-origin' header contains multiple values
我还尝试在web.config文件中添加一个条目,如下所示

<httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*"/>
        <add name="Access-Control-Allow-Headers" value="Content-Type, Accept" />
        <add name="Access-Control-Allow-Methods" value="GET, POST" />
        <add name="Access-Control-Max-Age" value="1728000" />
      </customHeaders>
    </httpProtocol>

有什么帮助吗?我想我现在可以解决这个问题了。请在
[ServiceContract]
中使用
*
。像这样:

[WebInvoke(Method = "*"
这样,您就可以允许您的方法接收选项请求[WebInvoke(Method = "*"