0

I am moved to a soap Web service ver 3.5. The post request are working fine for .net 4.5v. But while post data to service i am getting errors:

At browser

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

When i saw the details it is showing this

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()

My implementation is as:

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

And at service

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

inside web config:

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

How could i be able to call post request and get result in json format?

Hassaan
  • 3,931
  • 11
  • 34
  • 67

1 Answers1

0

From this Error: OPTIONS http://localhost/webserv/WebService1.asmx/HelloWorld I can assume you are facing CORS issue. There are two ways to solve these issue:

  1. On server side you need to add CORS headers. See this link for more information.
  2. Use Chrome browser: Open chrome browser using following command and browse to your page from where this service is getting called.

    chrome.exe --disable-web-security

Community
  • 1
  • 1
Pankaj Kapare
  • 7,486
  • 5
  • 40
  • 56