【问题标题】:how to post to soap web service from angularjs?如何从 angularjs 发布到肥皂网络服务?
【发布时间】:2015-01-12 19:17:50
【问题描述】:

我被转移到一个肥皂网络服务ver 3.5。发布请求适用于 .net 4.5v。但是在将数据发布到服务时,我遇到了错误:

在浏览器中

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);
}

内部网络配置:

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

我怎样才能调用 post 请求并获得 json 格式的结果?

【问题讨论】:

    标签: asp.net angularjs web-services soap asp.net-2.0


    【解决方案1】:

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

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

      chrome.exe --disable-web-security

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-29
      • 2017-01-16
      • 2017-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多