WCF错误:相对端点地址 [英] WCF Error : Relative end point addresses

查看:79
本文介绍了WCF错误:相对端点地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对WCF来说还很陌生.我想我有些混乱了.因此,这是我到目前为止所做的,并且已经在IIS中托管了WCF服务

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

首先签订合同

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

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>

和使用此网址的umhttp://localhost:7000/Service1.svc,而um出现此错误

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.

推荐答案

将服务端点地址设置为仅服务文件名(这是相对部分):

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

address="Service1.svc"

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

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

请参见此问题的答案

相关部分是:

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

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

这篇关于WCF错误:相对端点地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆