【发布时间】: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