1. Because my webservice is returning JSON,
2.ajax Delivery cross-domain insecure,
3.contentType:
"application/json; charset=utf-8"
, 这个是直接访问的webservice
So we're still using a background call ,
If you refer to Microsoft's WebService direct new object, calling the method will error the data at the root level is invalid
Troubled me for 1 days, the last solution,
Create an auxiliary class,
Public classWebservicehelper{ //<summary>///</summary>// <param name= "url" >Address</param>//<param Name= "method" >Method</param>//<param name= "param" >JSON Parameters</param> //<returns></returns>Public static StringWebserviceapp (stringURL,stringmethod,stringparam) { byte[] ByteArray =Encoding. UTF8. GetBytes ("json="+ param); HttpWebRequestwebRequest = (HttpWebRequest)WebRequest. Create (NewUri(URL +"/" + method)); Webrequest.method ="POST"; Webrequest.contenttype ="application/x-www-form-urlencoded"; Webrequest.contentlength = Bytearray.length; Streamnewstream = Webrequest.getrequeststream (); Newstream.write (ByteArray, 0, bytearray.length); Newstream.close (); HttpWebResponseresponse = (HttpWebResponse) Webrequest.getresponse (); StreamReaderphp =NewStreamReader(response. GetResponseStream (),Encoding. UTF8); stringphpend = php. ReadToEnd (); returnPhpend; } }
Call Method:
Webservice–3. Background call WebService, invalid data at root level