WCF Error : Relative end point addresses
Asked Answered
A

3

16

Um quite new to WCF . I think I have messed up a bit. So this is what I did so far and I ve hosted my WCF service in IIS

First the Contracts

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using YangkeeServer.dto;

namespace YangkeeServer
   {

public class Service1 : IService1
{
    [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "single")]
    public YangkeeTrailerDTO getTrailor()
    {
        return new YangkeeTrailerDTO()
        {
            loanFrom = "heaven"
        };
    }


    [WebInvoke(Method = "GET",
       ResponseFormat = WebMessageFormat.Json,
       UriTemplate = "datum/{id}")]
    public Test getName(string id)
    {
        return new Test()
        {
            Id = Convert.ToInt32(id) * 12,
            Name = "Leo Messi"
        };
    }
}
}

and this is my web.config file

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

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

  </system.web>
  <system.serviceModel>

    <services>

      <service name="YangkeeServer.Service1">

        <endpoint
          contract="YangkeeServer.IService1"
         binding="webHttpBinding"
         behaviorConfiguration="WebHttp"
         address="http://localhost:7000/Service1.svc">
       </endpoint>

     </service>

      <service name="YangkeeServer.Service2">

       <endpoint
          contract="YangkeeServer.IService2"
         binding="webHttpBinding"
         behaviorConfiguration="WebHttp"
         address="http://localhost:7000/Service2.svc">
       </endpoint>

     </service>

      <service name="YangkeeServer.YangkeeTrailer">

        <endpoint
          contract="YangkeeServer.IYangkeeTrailor"
          binding="webHttpBinding"
          behaviorConfiguration="WebHttp"
         address="http://localhost:7000/YangkeeTrailor.svc">
        </endpoint>

      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
       <behavior name="WebHttp">
         <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
   <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
 </system.serviceModel>
 <system.webServer>
   <modules runAllManagedModulesForAllRequests="true"/>
 </system.webServer>

 </configuration>

and um using this urlhttp://localhost:7000/Service1.svc and um getting this error

Server Error in '/' Application.

When 'system.serviceModel/serviceHostingEnvironment/multipleSiteBindingsEnabled' is set to true     in configuration, the endpoints are required to specify a relative address. If you are specifying a     relative listen URI on the endpoint, then the address can be absolute. To fix this problem, specify a relative uri for endpoint 'http://localhost:7000/Service1.svc'.

can any one tell me where did I do wrong? Thank you in advance.enter image description here

Abb answered 28/3, 2013 at 12:16 Comment(0)
C
36

Set the service endpoint address to just the service filename (this is the relative part):

address="Service1.svc"

or set the address to blank for each endpoint (I don't think its needed when hosting in the development environment or in IIS)

address=""

See this answer to another question

The relevant part is:

the virtual directory (in IIS) where your *.svc file exists defines your service endpoint's address.

Chief answered 1/4, 2013 at 4:13 Comment(1)
Thanks for the tip to set the address="", only way I could get it to work after adding multiple IIS host name bindings. Cheers.Nelda
M
10

To fix this error, I added... listenUri="/" ... to the service endpoint.

Example:

<service name="_name_">
  <endpoint address="http://localhost:_port_/.../_servicename_.svc"
    name="_servicename_Endpoint" 
    binding="basicHttpBinding"
    bindingConfiguration="GenericServiceBinding"
    contract="_contractpath_._contractname_"
    listenUri="/" />
</service>

MSDN: Multiple Endpoints at a Single ListenUri

Magnetochemistry answered 25/9, 2014 at 15:50 Comment(0)
L
3

This works for me:

1. Insert this lines inside service:

 <host>
      <baseAddresses>
        <add baseAddress="http://localhost:7000/Service1.svc" />
      </baseAddresses>
    </host>

2. Set the value of address as bellow:

address=""

The full code:

<service name="YangkeeServer.Service1">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:7000/Service1.svc" />
          </baseAddresses>
        </host>
        <endpoint
           contract="YangkeeServer.IService1"
          binding="webHttpBinding"
          behaviorConfiguration="WebHttp"
          address="">
        </endpoint>
      </service>
Libelee answered 23/2, 2017 at 18:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.