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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:29:08+00:00 2026-05-22T01:29:08+00:00

I am writing a service using wcf. I have created a solution with two

  • 0

I am writing a service using wcf.
I have created a solution with two projects:

  • Library: A project to store files concerning the services (containing the interface and the corresponding implementations for that service). This project is a library project.
  • Hosting application A project for hosting these services (self-hosting). For this reason, this project is an executable project having a config file where I put the information needed in order to configure the services.

I have also written a client in order to call the service. This will be referred to as the Client application.

I have a service. Following are the interface and the implementation (library project):

namespace EchoWcfLibrary {
    /// <summary>
    /// The interface specifies for those classes implementing it (services), the operation that the service will expose.
    /// </summary>
    [ServiceContract]
    public interface IService1 {
        // This does not use serialization (implicit serialization in considered: base types used).
        [OperationContract]
        string GetData(int value);
        // This uses data contracts and serialization.
        [OperationContract]
        CompositeType GetDataUsingDataContract(CompositeType composite);
    }

    [DataContract]
    public class CompositeType {
        // Members not serialized
        bool boolValue = true;
        string stringValue = "Hello ";
        // Serialized
        [DataMember]
        public bool BoolValue {
            get { return boolValue; }
            set { boolValue = value; }
        }
        // Serialized
        [DataMember]
        public string StringValue {
            get { return stringValue; }
            set { stringValue = value; }
        }
    }
}

Following is the startup of the service host application (the executable project):

namespace WcfServiceApplication {
    public static class Program {
        static void Main(string[] args) {
            // Setting endpoints and setting the service to start properly.
            // Base address specified: http://localhost:8081/Service1
            Console.WriteLine("Beginning...");
            using (ServiceHost host = new ServiceHost(typeof(Service1), new Uri("http://localhost:8081/Service1"))) {
                Console.WriteLine("Opening host...");
                host.Open();
                Console.WriteLine("Waiting...");
                System.Threading.Thread.Sleep(1000000);
                Console.WriteLine("Closing...");
                host.Close();
                Console.WriteLine("Quitting...");
            }
        }
    }
}

Following is the App.config in the executable project (hosting application):

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

    <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
    <system.serviceModel>
        <services>
            <service name="WcfServiceLibrary.Service1">
                <host>
                    <baseAddresses>
                        <add baseAddress="http://localhost:8081/Service1" />
                    </baseAddresses>
                </host>
                <!-- Service Endpoints -->
                <!-- Unless fully qualified, address is relative to base address supplied above -->
                <endpoint address="/GoInto/Svc" 
                                    binding="basicHttpBinding" 
                                    contract="WcfServiceLibrary.IService1">
                    <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
                    <identity>
                        <dns value="localhost"/>
                    </identity>
                </endpoint>
                <endpoint address="/GoInto/Sav"
                                    binding="basicHttpBinding"
                                    contract="WcfServiceLibrary.IService1">
                    <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
                    <identity>
                        <dns value="localhost"/>
                    </identity>
                </endpoint>
                <!-- Metadata Endpoints -->
                <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
                <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
                <endpoint address="GoInto/Mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
            </service>
        </services>

        <behaviors>
            <serviceBehaviors>
                <behavior>
                    <!-- To avoid disclosing metadata information, 
          set the value below to false and remove the metadata endpoint above before deployment -->
                    <serviceMetadata httpGetEnabled="True"/>
                    <!-- To receive exception details in faults for debugging purposes, 
          set the value below to true.  Set to false before deployment 
          to avoid disclosing exception information -->
                    <serviceDebug includeExceptionDetailInFaults="False" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
    </system.serviceModel>

</configuration>

Following is the program startup in the client executable project (a link to library project has been made), basically this is the client:

namespace WcfServiceClient {
    class Program {
        static void Main(string[] args) {
            ServiceEndpoint httpEndpoint = new ServiceEndpoint(ContractDescription.GetContract(typeof(IService1)), new BasicHttpBinding(), new EndpointAddress("http://localhost:8081/Service1"));
            ChannelFactory<IService1> channelFactory = new ChannelFactory<IService1>(httpEndpoint);
            IService1 svc = channelFactory.CreateChannel();
            Console.WriteLine(svc.GetData(121));
            System.Threading.Thread.Sleep(10000);
        }
    }
}

Well… My problem is the following: this application WORKS!!!
Why is it a problem???
The problem is that I specified, when hosting the service, in the App.config file, three endpoints: two basicHttp and one metadata endpoint. Well, I would like to address the <endpoint address="/GoInto/Svc"... endpoint which has, I assume this to be the complete address (note that I have specified a base address): http://localhost:8081/Service1/GoInto/Svc.

Well, unfortunately, in the client, I address this endpoint: http://localhost:8081/Service1 which is just the base address…… WHY DOES IT WORK???? I want to specify this address in the client:

namespace WcfServiceClient {
    class Program {
        static void Main(string[] args) {
            ServiceEndpoint httpEndpoint = new ServiceEndpoint(ContractDescription.GetContract(typeof(IService1)), new BasicHttpBinding(), new EndpointAddress("http://localhost:8081/Service1/GoInto/Svc"));
            ChannelFactory<IService1> channelFactory = new ChannelFactory<IService1>(httpEndpoint);
            IService1 svc = channelFactory.CreateChannel();
            Console.WriteLine(svc.GetData(121));
            System.Threading.Thread.Sleep(10000);
        }
    }
}

But if I do this, a mismatch error is raised:

The message with To
‘http://localhost:8081/Service1/GoInto/Svc&#8217;
cannot be processed at the receiver,
due to an AddressFilter mismatch at
the EndpointDispatcher. Check that
the sender and receiver’s
EndpointAddresses agree.

Why doesn’t it work?

  • 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-22T01:29:08+00:00Added an answer on May 22, 2026 at 1:29 am

    The base address must be specified in one place, either on the ServiceHost constructor, or in the element. If you have in both places, WCF will throw an exception saying that you have two base addresses for the same scheme (HTTP).

    What is likely happening is that you have a mismatch on the service name on app.config of the hosting project, so that configuration is not being picked up (and what you get is a default endpoint, whose address is at the same one as the base address). Try adding the foreach loop on your hosting code, and you should see the addresses of the endpoints your service is listening at.

                    Console.WriteLine("Opening host...");
                host.Open();
    
                foreach (ServiceEndpoint endpoint in host.Description.Endpoints)
                {
                    Console.WriteLine("Endpoint:");
                    Console.WriteLine("   Address: {0}", endpoint.Address.Uri);
                    Console.WriteLine("   Binding: {0}", endpoint.Binding);
                    Console.WriteLine("   Contract: {0}", endpoint.Contract.Name);
                }
    
                Console.WriteLine("Waiting...");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a web service using WCF. I created data contracts. I created
I'm writing a WCF service for the first time. The service and all of
I'm writing a windows service which will be used to monitor some other services
I'm writing a Win32 service in C++. I have a custom Assert macro that
I'm writing RESTful service with C#/wcf and need to put filters on GET. Like
I'm writing a service that has five different methods that can take between 5
I'm writing a web service, and I want to return the data as XHTML.
I am writing a Windows service that pulls messages from an MSMQ and posts
I am writing a windows service. This service runs another process I've developed through
I am writing a windows service in VS2008 - c#. When I double click

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.