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 6334445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:39:35+00:00 2026-05-24T18:39:35+00:00

I am trying to make a call from a Silverlight application to a WCF

  • 0

I am trying to make a call from a Silverlight application to a WCF service returning JSON. It’s simply returning an integer. I have used Fiddler to verify that it is never making the call to my webservice. I am getting an error that says “Operation is not valid due to the current state of the object.” It occurs on the line, HttpWebResponse response = (HttpWebResponse) _webRequest.EndGetResponse(result); Stacktrace can be provided if needed.

public MainPage()
    {
        InitializeComponent();

        StartWebRequest();
    }

    void StartWebRequest()
    {
        HttpWebRequest _webRequest = (HttpWebRequest)WebRequest.Create(new Uri("http://www.example.com/MyJSON.svc/onlineusercount"));

        _webRequest.ContentType = "text/json";
        _webRequest.Method = "GET";
        _webRequest.BeginGetResponse(FinishWebRequest, _webRequest);
    }

    void FinishWebRequest(IAsyncResult result)
    {
        HttpWebRequest _webRequest = (HttpWebRequest)result.AsyncState;

        HttpWebResponse response = (HttpWebResponse)_webRequest.EndGetResponse(result);
        Stream streamResponse = response.GetResponseStream();
        StreamReader streamRead = new StreamReader(streamResponse);
        string responseString = streamRead.ReadToEnd();
        needle.Value = Convert.ToInt32(responseString);

        // Close the stream object
        streamResponse.Close();
        streamRead.Close();

        // Release the HttpWebResponse
        response.Close();
    }
}

UPDATE: I have commented out the line above that says

_webRequest.ContentType = "text/json";

My new error says: SecurityException unhandled by user code. I believe this means I should use a try catch, but I am not sure what type of exception to catch.

My stack trace is as follows:

at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at FuelizerGuage.MainPage.FinishWebRequest(IAsyncResult result)
at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClassd.<InvokeGetResponseCallback>b__b(Object state2)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

Also according to Fiddler, my silverlight application is now making at call to my webservice domain looking for clientaccesspolicy.xml and then looks for crossdomain.xml, neither of which exist.

  • 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-24T18:39:36+00:00Added an answer on May 24, 2026 at 6:39 pm

    “GET” requests cannot have a Content-Type header (they cannot have content). The HttpWebRequest implementation in Silverlight is more strict than the one in the desktop framework. Try removing the ling which defines that property and it should work.

    Update: you’re hitting a cross-domain problem in your application. To prevent some kinds of cross-domain attacks, SL requires that any requests going to a domain other than the one where the SL applicaiton (the .xap file) originated to be subject to a cross-domain policy – they’re disallowed by default. You can find more information about this at http://msdn.microsoft.com/en-us/library/cc645032(VS.95).aspx.

    To solve this problem you’ll essentially have to add a cross-domain policy to your service to allow SL apps to consume it.

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

Sidebar

Related Questions

I'm trying to make a call to a remote WCF service from within an
Trying to make a web service call to an HTTPS endpoint in my Silverlight
When trying to make a web service (hosted on a different server) call from
I am trying to make a call to a Parent class method from a
I'm trying to make an external call to the google maps application on the
I trying to make my first AJAX with JSON call using jQuery and CodeIgniter.
I am trying to make a web service request call to a third part
I'm trying to make a call to a DLL function (via GetProcAddress etc) from
I trying to make a web service accessible to Matlab. I can call it
I am trying to make an AJAX call from several domains to a single

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.