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

  • Home
  • SEARCH
  • 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 4106164
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:20:28+00:00 2026-05-20T21:20:28+00:00

I’m trying to use ASMX/WCF to pass objects between sites (public / private). I

  • 0

I’m trying to use ASMX/WCF to pass objects between sites (public / private). I can get the serialized object from my private ASMX service to my public WCF service, but I can’t deserialize the object. Code below followed by error.

WCF service that calls a private ASMX service.

[WebGet(UriTemplate = "{part}")]
public Distributor GetDistributorInventory(string part)
{
    const string url = "http://www.site.com/service/lookup.asmx/StockCheck?part=" + part;
    //This is a wrapper for a HttpWebRequest that returns a string
    string results = WebHelper.HttpRequest("GET", "text/xml", null, url, new CookieContainer());  
    byte[] byteArray = Encoding.ASCII.GetBytes(results);
    MemoryStream stream = new MemoryStream(byteArray);
    DataContractSerializer deserialize = new DataContractSerializer(typeof(Distributor));
    return (Distributor)deserialize.ReadObject(stream);
}

Contract used in both Public/Private Services

[DataContract(Namespace = "http://www.site.com/Services/", Name = "Inventory")]
public class Inventory
{
    [DataMember(Order = 1)]
    public string MPN{ get; set; }
    [DataMember(Order = 2)]
    public string DataSheetURL { get; set; }
    [DataMember(Order = 3)]
    public List<Distributor> Stock { get; set; }
}

[DataContract(Namespace = "http://www.site.com/Services/", Name = "Distributor")]
public class Distributor
{
    [DataMember(Order = 1)]
    public string Name { get; set; }
    [DataMember(Order = 2)]
    public string Part { get; set; }
    [DataMember(Order = 3)]
    public int Quantity { get; set; }
    [DataMember(Order = 4)]
    public string URL { get; set; }
}

Error Message:

Error in line 1 position 166. Expecting element ‘Distributor’ from namespace ‘http://www.site.com/Services/&#8217;.. Encountered ‘Element’ with name ‘Inventory’, namespace ‘http://www.site.com/Services/&#8217;.

I might be going about this the entirely wrong way, so suggestions on a better approach (with sample) would greatly appreciate. My end goal is to pass objects between WCF & WCF or ASMX services using custom objects and DataContracts.

  • 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-20T21:20:29+00:00Added an answer on May 20, 2026 at 9:20 pm

    Here is the final solution I found for making this work, with the least amount of work possible.

    1. I switched from passing my object as XML to JSON (was my final goal, tho I started with XML)

    2. After getting my JSON object received, I noticed it had a wrapper “d:” and had a property “__type:” that was being added. Knowing these needed to be removed, I decided to find a generic way to remove the elements.

    3. My generic solution was to use this code/article on Codeplex that had extension methods that did the clean-up using Reg Ex. Very simple.

    Here is my resulting code:

    [WebGet(UriTemplate = "{part}")]
    public Distributor GetDistributorInventory(string part)
    {
      const string url = "http://www.site.com/service/lookup.asmx/StockCheck";
      string results = WebHelper.HttpRequest("POST", "application/json; charset=utf-8", "{part: " + part + "}", url, new CookieContainer());
    
      Inventory inventory = new JavaScriptSerializer().CleanAndDeserialize<Inventory>(results);
    
      return inventory;
    }
    

    Another perk to this solution, is the ability to convert the object regardless of namespace. This results in being able to use the object “sender.Inventory” in my source ASMX service and the object “receiver.Inventory” in my WCF service where I’m going to consume the object.

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

Sidebar

Related Questions

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
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.