2013-03-28 5 views
12

Ум совершенно новый для WCF. Кажется, я немного испортил. Так это то, что я сделал до сих пор, и я ве принимала мою службу WCF в IISWCF Ошибка: Относительные адреса конечных точек

Первые Договоры

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" 
     }; 
    } 
} 
} 

и это мой файл web.config

<?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> 

и ит с помощью этого urlhttp: // локальный: 7000/Service1.svc и гм получаю эту ошибку

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'. 

может любой сказать мне, где я сделал не так? Заранее спасибо. enter image description here

ответ

28

Установите на конечную точку адреса только имя файла сервиса (это относительная часть):

address="Service1.svc" 

или установить адрес заготовки для каждой конечной точки (я не думаю, что его нужно при размещении в среда разработки или в IIS)

address="" 

См this answer to another question

соответствующая часть:

виртуальный каталог (в IIS), где существует ваш * .svc-файл, определяет адрес вашей конечной точки службы.

+1

Спасибо за кончик, чтобы установить адрес = «», только так я мог заставить его работать после того, как добавление нескольких привязок имени узла IIS. Приветствия. –

+0

Спасибо, это сработало для меня тоже :) –

9

Чтобы исправить эту ошибку, я добавил ... listenUri = "/" ... для конечной точки службы.

Пример:

<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

+1

Большое спасибо ... это работает .. –

0

Это работает для меня:

1. Вставьте эти строки внутри службы:

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

2. Установите значение из адрес как ниже:

адрес = «»

Полный код:

<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>