通过Android消费WCF Post Rest服务时出现400 Bad Request错误

时间:2013-10-26 04:13:51

标签: javascript wcf post cross-domain wcf-rest

当我尝试使用Android java Application调用WCF post Rest服务时,我一直收到404 Bad Request。当我使用javascript测试服务时,我得到相同的错误。

我的WCF运营合同

[OperationContract]
        [WebInvoke(Method = "POST",
            ResponseFormat = WebMessageFormat.Json,
            RequestFormat=WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped,
            UriTemplate = "signature")]
        string signature(Signature rData);

我的签名功能

 public string signature(Signature rData)
        {


            return "accepted";
        }

使用javascript进行客户端编码

function post() {
 var persona = {
        IdPersona: "2",
        Nombre: 'David BQ'
    };
    var xhr = new XMLHttpRequest();
    xhr.open('POST', 'http://mylocalurl.com/RestServiceImpl.svc/auth', true);
    xhr.setRequestHeader("Content-type", "application/x-javascript");
    xhr.onload = function () {
      console.log(this.responseText);
};
xhr.send(persona);
}

这里我尝试使用application / x-javascript和application / json作为内容类型

我收到了错误

XMLHttpRequest无法加载http://mylocalurl.com/RestServiceImpl.svc/auth。 Access-Control-Allow-Origin不允许原点http://tempurl.com

浏览器控制台中的

我该如何解决这个问题。如果它在浏览器中工作正常,我相信我可以用JAVA做到这一点。 请帮忙

0 个答案:

没有答案
相关问题