Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6544261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:26:39+00:00 2026-05-25T11:26:39+00:00

I’m trying to setup a WCF web service to be consumed by JavaScript using

  • 0

I’m trying to setup a WCF web service to be consumed by JavaScript using JSON and jQuery. I’ve noticed that you can send JSON without a DataContract if the service method parameters match the naming structure of the JSON object:

<ServiceContract(Namespace:="http://foo.com/bar")>
<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)>
Public Class WebServices

    <OperationContract()>
    Public Function Test(fullname As String)

        Return CustomFunctions.SerializeJSON(New With {
                                                .SSN = "999-99-9999",
                                                .Birthday = "9/22/1983"})
    End Function

End Class

…And JavaScript…

$.ajax({
    url: "webservices.svc/Test",
    data: JSON.stringify({
        "fullname" : "John Smith"
     }),
    type: "POST",
    processType: false,
    contentType: "application/json; charset=utf-8",
    dataType: "text",
    success: function (result)
    {
        console.log(result);
    },
    error: function (xhr)
    {
        console.log(xhr.responseText);
    }
});

This works great, but I can see an issue coming up if I want to send the web service a lot of data. Naturally the parameter list is going to get really long and ugly. The alternative is to create a DataContract. However I’m most likely going to be creating a lot of web services and I don’t want to have to create a brand new DataContract every time I want to send data longer than 5 key-value pairs.

What I’m hoping is that there’s a way to access the incoming JSON object as a Dictionary(Of String, Object) through the method parameter:

<OperationContract()>
Public Function Test(data As Dictionary(Of String, Object))
   Dim firstName As String = data("FirstName")
   Dim lastName as String = data("LastName")

   '...logic goes here...

   '....return JSON object

End Function

Does anyone know if this is possible? What do most people do in this scenario? I had this working great in ASMX so I know it’s possible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:26:40+00:00Added an answer on May 25, 2026 at 11:26 am

    Ok I think I figured out how to do this (for those interested). I need to bypass the DataContracts (nothing against DataContracts, they’re just a litte much when the only client is my AJAX code). In order to do this I changed the web service method to look like this:

    <OperationContract()>
    <WebInvoke(Method:="POST", BodyStyle:=WebMessageBodyStyle.Bare, ResponseFormat:=WebMessageFormat.Json)>
    Public Function Test(request As Stream) As String
        Using reader As New StreamReader(request)
            Dim serializer As New JavaScriptSerializer()
            Dim data As Dictionary(Of String, Object) = serializer.Deserialize(Of Dictionary(Of String, Object))(reader.ReadToEnd())
    
            Dim firstName As String = data("FirstName")
            Dim lastName As String = data("LastName")
    
            Return serializer.Serialize(New With {.SSN = "999-99-9999",
                                                  .Birthday = "9/22/1983"})
        End Using
    End Function
    

    This will take in the request as a raw stream and leave the deserialization up to me (which I actually prefer – the less magic the better).

    The AJAX didn’t change much except for the fact that I needed to remove the contentType (leave it as default) and change the dataType of the response to json (when it was “text” I needed to deserialize it twice for some reason):

    $.ajax({
        url: "webservices.svc/Test",
        data: JSON.stringify({
            "FirstName": "John",
            "LastName": "Smith"
        }),
        type: "POST",
        dataType: "json",
        success: function (result)
        {
            var data = JSON.parse(result);
            console.log(data.SSN);
        },
        error: function (xhr)
        {
            console.log(xhr.responseText);
        }
    });
    

    I hope this helps anyone wanting to avoid DataContracts.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.