2015-01-12 47 views
0

我被转移到肥皂Web服务ver 3.5。发布请求正常工作.net 4.5v。不过,虽然数据发布到服务,我会收到错误:如何从angularjs发布到soap web服务?

在浏览器

Error: OPTIONS http://localhost/webserv/WebService1.asmx/HelloWorld 
XMLHttpRequest cannot load http://localhost/webserv/WebService1.asmx/HelloWorld. Invalid HTTP status code 500 

,当我看到的细节它显示这个

System.InvalidOperationException: Missing parameter: obj. 
    at System.Web.Services.Protocols.ValueCollectionParameterReader.Read(NameValueCollection collection) 
    at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters() 
    at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest() 

我的实现是:

$http({ 
method: 'POST', 
url: 'http://localhost/webserv/WebService1.asmx/HelloWorld', 
datatype: 'json', 
data:JSON.stringify({obj:details}) 
contentType: "application/json; charset=utf-8" 
}).success(function(data,status, headers, config){ 
    if(status == '200'){ 
    alert(data.d); 
    } 
}).error(function(data,status, headers, config){}); 

并服务于

[WebMethod] 
[ScriptMethod(ResponseFormat = ResponseFormat.Json)] 
public string HelloWorld(Details obj) 
{ 
    return JsonConvert.SerializeObject((new Helper()).GetDetails(obj.Id); 
} 

web配置中:

<protocols> 
    <add name="HttpGet"/> 
    <add name="HttpPost"/> 
    </protocols> 

我怎么会是能够调用POST请求,并得到导致JSON格式?

回答

0

从这个 错误:OPTIONS http://localhost/webserv/WebService1.asmx/HelloWorld我可以假设你面临着CORS问题。 有两种方法可以解决这些问题:

  1. 在服务器端,您需要添加CORS标头。有关更多信息,请参阅此link
  2. 使用Chrome浏览器: 使用以下命令打开Chrome浏览器并浏览到您的页面,从中调用该服务。

    的chrome.exe - 禁用网络安全