Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.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

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# 起源http://myurl2/client wcf post服务中的访问控制允许来源不允许_C#_Wcf_Rest_Xmlhttprequest_Cross Domain - Fatal编程技术网

C# 起源http://myurl2/client wcf post服务中的访问控制允许来源不允许

C# 起源http://myurl2/client wcf post服务中的访问控制允许来源不允许,c#,wcf,rest,xmlhttprequest,cross-domain,C#,Wcf,Rest,Xmlhttprequest,Cross Domain,我要走了 无法加载XMLHttpRequest。访问控制不允许原点允许原点。 调用用WCF Rest编写的Post服务时,我的客户端Javascript应用程序中出现此错误 我的服务 [OperationContract] [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json,

我要走了

无法加载XMLHttpRequest。访问控制不允许原点允许原点。 调用用WCF Rest编写的Post服务时,我的客户端Javascript应用程序中出现此错误

我的服务

[OperationContract]
        [WebInvoke(Method = "POST",
            ResponseFormat = WebMessageFormat.Json,
            RequestFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped,
            UriTemplate = "post")]
        bool JSONDataPost(string Value);


public bool JSONDataPost(string Value)
        {   //code to Create the Person goes here

            return true;
        }
我的客户要求是

var xhr = new XMLHttpRequest();
    xhr.open('POST', 'http://myurl.com/RestServiceImpl.svc/post', true);
    xhr.setRequestHeader("Content-Type", "application/jsonp;charset=UTF-8");
    xhr.onload = function () {
        // do something to response

    console.log(this.responseText);
    };
    xhr.send(JSON.stringify("TEST"));

您需要获得
http://myurl.com/RestServiceImpl.svc/post
发送
OPTIONS
动词请求时,使用
CORS
标题进行响应。我建议您切换到
ASP.Net Web API
,因为您可以更好地控制REST谓词响应。另外,
application/jsonp
不是有效的内容类型,
“TEST”
不是有效的JSON。您应该分别使用
application/json
{“TEST”:“helloworld!”}