WCF错误:相对终点地址(WCF Error : Relative end point addres

2019-08-18 03:11发布

庵很新的WCF。 我想我已经搞砸了一下。 所以这是我做的,到目前为止,我已经托管在IIS中我的WCF服务

首先,合同

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>

和UM使用此urlhttp://本地主机:7000 / Service1.svc和UM收到此错误

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

任何一个可以告诉我在哪里我做错了什么? 先感谢您。

Answer 1:

设置服务端点地址只是该服务名(这是相对的部分):

address="Service1.svc"

或设置地址为空的每个端点(在开发环境中或在IIS托管时,我不认为它需要)

address=""

见这个回答另一个问题

相关部分是:

在您的* .svc文件所在的虚拟目录(在IIS)定义了你的服务端点的地址。



Answer 2:

要修正这个错误,我加... listenUri =“/” ...的服务端点。

例:

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

MSDN:在单ListenUri多个端点



Answer 3:

这对我的作品:

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>


文章来源: WCF Error : Relative end point addresses