I'm trying to send multiple parameters to a WCF service. Server side I log the incoming data. Where errors 1 and 2 are logged, but 3 and 4 are not. I tried debugging to be able to step through, but the client-side javascript call is not triggering my server-side code so I can step through.
What am I missing?
Request payload from Chrome Developer Console:
<script type="text/javascript">
$(document).ready(function () {
var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://www.example.com/api/multipleparams');
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({ str: { "idtoken": "e46541", "lang": "dfgfdgfdg" } }));
});
</script>
<Runtime.Serialization.DataContract>
Public Class oAuthUserSigninDetails
Private _idtoken As String
<Runtime.Serialization.DataMember>
Public Property idtoken As String
Get
Return _idtoken
End Get
Set(ByVal value As String)
_idtoken = value
End Set
End Property
Private _lang As String
<Runtime.Serialization.DataMember>
Public Property lang As String
Get
Return _lang
End Get
Set(ByVal value As String)
_lang = value
End Set
End Property
End Class
<OperationContract()>
<Web.WebInvoke(Method:="POST", ResponseFormat:=Web.WebMessageFormat.Json, BodyStyle:=Web.WebMessageBodyStyle.Bare, UriTemplate:="multipleparams")>
Function multipleparams(ByVal str As oAuthUserSigninDetails) As Stream
Public Function multipleparams(ByVal str As oAuthUserSigninDetails) As Stream Implements Iapi.multipleparams
LogError("1 multipleparams")
LogError("2 str", str.ToString)
LogError("3 idtoken", str.idtoken.ToString)
LogError("4 lang", str.lang.ToString)
End Function
CodePudding user response:
I think 3 and 4 are not logged because they have null values and ToString cause a null exception and since they are both string you don't need to use ToString at all.
When you accept a class as an argument in your OperationContract, I don't think you need to specify the argument name when you posting a JSON request.
xhr.send(JSON.stringify({ "idtoken": "e46541", "lang": "dfgfdgfdg" }));