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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:33:35+00:00 2026-05-26T05:33:35+00:00

I would like to create a service which returns a simple string. So far

  • 0

I would like to create a service which returns a simple string. So far I have created a WCF REST Service using Template 40(CS) the following way:

Service class:

    namespace MobileREST
    {
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    public class UserService
    {
        [WebGet(UriTemplate = "IMSI={i}", ResponseFormat = WebMessageFormat.Json)]
        public string GetUsername(string i)
        {
            string username = DBWorks.GetUserName(i);
            return username;
        }
    }
}

Web.config:

<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true">
      <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </modules>


  </system.webServer>

  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <standardEndpoints>
      <webHttpEndpoint>
        <!-- 
            Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
            via the attributes on the <standardEndpoint> element below
        -->
        <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/>
      </webHttpEndpoint>
    </standardEndpoints>
  </system.serviceModel>

  <connectionStrings>
    <add name="LocalDBString" connectionString="Data Source=.\sqlexpress;Initial Catalog=MobileRestDB;Integrated Security=True"/>
    <add name="SecurityConnString" connectionString="Data Source=.\sqlexpress;Initial Catalog=LopataDB;Integrated Security=True" />
  </connectionStrings>

</configuration>

The solution works fine while debugging, but I haven’t found the way to host this service in windows (console) application or IIS in order to expose the service.

The client is supposed to create GET or POST requests and receive short answers. In debug mode the request to http://localhost:portNumber/UserService/IMSI=xxx returns just a string xxx (without http headers) which is perfect but I don’t know how to expose the same solution in order to host it at http://customWebAddress/UserService/IMSI=xxx and get the same result.

I would really appreciate if anyone could suggest any solution or provide any useful resource regarding the above problem.

  • 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-26T05:33:35+00:00Added an answer on May 26, 2026 at 5:33 am

    To self-host this (in a console app or a NT Service), use something along the lines of this:

    class Program
    {
        static void Main(string[] args)
        {
            Uri baseAddress = new Uri("http://localhost:6677/UserService");
            WebServiceHost host = new WebServiceHost(typeof(UserService), 
                                                     new Uri[] { baseAddress });
    
            host.Open();
    
            Console.ReadLine();
    
            host.Close();
        }
    }
    

    That creates an instance of the WebServiceHost which is the service host descendant that knows how to handle REST services, and establishes a base address for your service to be called on.

    Once this app is running, you should be able to browse to http://localhost:6677/UserService and see your service there…

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

Sidebar

Related Questions

I have a service which returns an Array of ObjectProxy objects. I would like
i'd like to create a windows service that would be accessible via WCF from
I have an existing web service that returns XML responses and I would like
I would like create a web service in ASP.Net 2.0 that will supports JSON.
I created and binded a service in an activity and I would like to
I would like to create a database backed interactive AJAX webapp which has a
I have created a dummy web service with 2 optional parameters using the .Net
I am trying to create WCF Data service project using Entity Framework. ( I
I would like create my own collection that has all the attributes of python
Would like to create a strong password in C++. Any suggestions? I assume it

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.