मेरे पास एक पूर्णांक के साथ एक एएसपीनेट webservice कॉल है। हमारे विरासत एप्लिकेशन पर जो .NET 4.0 को पोर्ट किया गया था, मुझे यह कॉल काम पर नहीं मिल सकती है। मैं एक तरीका है जिसके कोई पैरामीटर लेकिन वेब विधि को डाटा भेजने निम्नलिखित त्रुटि देता है कॉल कर सकते हैं:एएसपीनेट एएसएमएक्स वेब सेवा फेंकने के लिए jQuery अजाक्स अनुरोध प्रारूप अमान्य है: एप्लिकेशन/जेसन
System.InvalidOperationException: Request format is invalid: application/json; charset=UTF-8.
at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
मैं एक खाली परियोजना में बिल्कुल एक ही कोड बनाया है और यह ठीक काम किया। मैं web.config में कुछ भी नहीं देख सका कि रिक्त प्रोजेक्ट ने जोड़ा जो इससे फर्क पड़ेगा।
jQuery कोड
$.ajax({
type: "POST",
url: "/WebService1.asmx/Test",
data: JSON.stringify({"code": 1234}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert(msg);
}
});
मेरे वेब सेवा कोड
<ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class WebService1
Inherits WebService
<WebMethod()>
Public Function Test(ByVal code As Integer) As String
Return "success"
End Function
<WebMethod()>
Public Function Hello() As String
Return "hello"
End Function
End Class
वेब कॉन्फ़िग
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appSettings>
</appSettings>
<connectionStrings>
</connectionStrings>
<system.web>
<httpRuntime enableVersionHeader="false" />
<httpCookies httpOnlyCookies="true" requireSSL="false" lockItem="true" />
<trace enabled="false" pageOutput="true" requestLimit="40" localOnly="true"/>
<httpModules>
</httpModules>
<compilation debug="true" strict="true" explicit="true" targetFramework="4.0">
</compilation>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
</pages>
<authentication mode="Forms">
<httpHandlers>
</httpHandlers>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules>
</modules>
<handlers>
</handlers>
<httpErrors errorMode="Custom" >
</httpErrors>
</system.webServer>
</configuration>
क्या आप अपनी web.config फ़ाइल पोस्ट कर सकते हैं? मुझे पता है कि समस्या कहां है, जवाब देने से पहले मुझे केवल एक पुष्टिकरण की आवश्यकता है। –
@DarinDimitrov मैंने web.config जोड़ा है लेकिन संवेदनशील विवरण हटा दिया है – skyfoot