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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:10:05+00:00 2026-06-14T09:10:05+00:00

I’m supposed to reach a resource using JS from our server. I’ve set up

  • 0

I’m supposed to reach a resource using JS from our server. I’ve set up the code below.

var targetUrl = "http://somePlace.com/actualResourceName";
var xdr = new XDomainRequest();
xdr.onload = function () { alert(xdr.responseText); }
xdr.open("GET", targetUrl);
xdr.send();

However, I’m not clear how the method on the other side needs to be created. I’ve come up with the following suggestion, fully aware that it’s not working. I’m sure I’m missing the right attributes, for instance. I’m not even sure where to set that the method is supposed to react on actualResourceName…

[???]
public String ActualResourceName()
{
  return "Bye, bye, cruel word!";
}

I’ve googled around but I haven’t found any solution. I might have stumbled across it without realizing that it’s something useful, though.

How should the method in C# be written?

  • 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-06-14T09:10:07+00:00Added an answer on June 14, 2026 at 9:10 am

    OK, here it goes. I’ll describe two ways to get it done, easiest ones:

    1. ASP.NET WebApi

    You’ll have to create a new ASP.NET MVC4 project (be it release or RC), select the ‘WebApi’ as an option:
    Project startup

    And you’ll have the template ready. Now you right click ‘Controllers’ folder, then
    Add -> Controller:
    enter image description here

    and fill it out e.g. like that:

    public class ActualResourceController : ApiController
    {
        public string Get()
        {
            return "Hey there! Getting the resource...";
        }
    }
    

    Default routes are in Global.asax, when you go to definition of WebApiConfig.Register(...) method, you’ll see that the default route is host/api/controller.
    Let’s try that out, when you start up the project and go under (in my case, the port is chosen automatically by the development server) http://localhost:23030/api/ActualResource
    you’ll get:

    <string>Hey there! Getting the resource...</string>
    

    WebApi returns either JSON or XML depending on the Accept header, if you want JSON to be the only one/default, take a look at this link.

    You can of course create a class and return it, it will get serialized to XML/JSON in a similar fashion you’ll see below with ServiceStack.


    2. ServiceStack

    Now the ServiceStack is powerful, open-source REST web-service framework. It works a little bit different than WebApi, and here’s a quick introduction (although the documentation is good):

    Create the regular ASP.NET MVC project (in my case, MVC4) – you’ll have an empty template:

    service stack startup project

    Then fire up the Package Manager Console and type (like the documentation suggests) Install-Package ServiceStack.Host.Mvc, which will get you a ServiceStack project template with a tutorial app and such which you can later on remove if you wish.

    But first things first, the ServiceStack works on DTOs, the Request-Response objects. So let’s create them, the ActualResource class which will serve as a request and ActualResourceResponse which will be a response. Since you have no parameters in a request, the first one is trivial:

    public class ActualResource
    {
    }
    

    Any parameters would be automatic properties. Now the response:

    public class ActualResourceResponse
    {
        public string ResourceName { get; set; }
    }
    

    And the service class itself:

    public class ActualResourceService : Service
    {
        public object Get(ActualResource request)
        {
            return new ActualResourceResponse {
               ResourceName = "Hi! It's the resource name." };
        }
    }
    

    You could of course return bare string for your current purposes, it would work all the same.

    Now in the template ServiceStack creates, everything happens in AppHost.cs file, let’s take a look and modify it a tiny little bit:

    Routes
        .Add<Hello>("/hello") 
        .Add<Hello>("/hello/{Name*}")
        .Add<Todo>("/todos")
        .Add<Todo>("/todos/{Id}") //everything up to here are a template/tutorial routes, you can safely remove them
        .Add<ActualResource>("/actualResource"); //and here you add a route to your own service
    

    For it to work, you have to go to Global.asax and comment out the whole WebApiConfig.Register(GlobalConfiguration.Configuration) line, then go into the RouteConfig.RegisterRoutes method and add:

     routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
     routes.IgnoreRoute("api/{*pathInfo}"); // <<<---- this line
     routes.MapRoute(
          name: "Default",
          url: "{controller}/{action}/{id}",
          defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
      );
    

    A little more plumbing is required, but it’s still not bad.

    Now when you start the service, go under localhost:whateverport/api/actualResource, you’ll get the familiar string, and here’s a screenshot:
    ServiceStack reply page

    ServiceStack can serialize to various formats, so if you go under http://localhost:yourPort/api/actualResource?format=json, you’ll get:

    {"resourceName":"Hi! It's the resource name."}
    

    if ?format=xml, then:

    <ActualResourceResponse>
        <ResourceName>Hi! It's the resource name.</ResourceName>   
    </ActualResourceResponse>
    

    And so on…

    Now the ServiceStack setup is a bit more complicated, but it supports e.g. Memcache out of the box, you can plumb in Redis, you can use various authentication providers, all of that may be quite useful in some scenarios. But, as Uncle Ben once said, “with great power comes great responsibility”, and a bit harder setup phase…


    Now you can choose whichever you feel like, these two are the simplest options right now IMHO. Of course it’s only a simple tutorial to get you started, you’ll have a chance to explore this topic in depth when you get going with the project.

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
Does anyone know how can I replace this 2 symbol below from the string
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.