WCF-C的URL中的Suprime .svc#

时间:2017-09-01 19:27:32

标签: wcf

我开始使用WCF - C#,因为我需要制作一个大型项目,我发现了以下问题: 我试图在服务WCF的URL中删除带有以下代码的.svc扩展名:

using System.Web;    
namespace PruebaWCFEndpoint
{
    public class RemoveSvc : IHttpModule
    {
        public void Dispose()
        {
        }

        public void Init(HttpApplication context)
        {
            context.BeginRequest += delegate
            {

                HttpContext ctx = HttpContext.Current;
                string path = ctx.Request.AppRelativeCurrentExecutionFilePath;
                path = path.Replace("Hola.svc", "Hola");
                ctx.RewritePath(path, null, ctx.Request.QueryString.ToString(), false);
            };

        }
    }
}

以下代码是web.config:

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

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5"/>
    <httpRuntime targetFramework="4.5"/>
    <httpModules>
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
    </httpModules>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="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>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https"/>
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <remove name="ApplicationInsightsWebTracking"/>
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"
        preCondition="managedHandler"/>
      <!--
        The follow line was added by myself *************
      -->
      <add name ="removesvc" type="PruebaWCFEndpoint.RemoveSvc,PruebaWCFEndpoint"/>
      <!--
      ******************************
      -->
    </modules>
    <directoryBrowse enabled="true"/>
    <validation validateIntegratedModeConfiguration="false"/>
  </system.webServer>

</configuration>

但是我正在测试并且&#34; WCF测试客户端&#34;工具显示以下消息:

Error: Cannot obtain Metadata from http://localhost:9086/Hola.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://localhost:9086/Hola.svc Los metadatos contienen una referencia que no se puede resolver: 'http://localhost:9086/Hola.svc'. El tipo de contenido text/html; charset=utf-8 del mensaje de respuesta no coincide con el tipo de contenido del enlace (application/soap+xml; charset=utf-8). Si usa un codificador personalizado, aseg£rese de que el m‚todo IsContentTypeSupported se implemente correctamente. Los primeros 1024 bytes de la respuesta fueron: ' 
HTTP Error 500.0 - Internal Server Error

服务界面如下:

using System.ServiceModel;

namespace PruebaWCFEndpoint
{
    [ServiceContract]
    public interface IHola
    {
        [OperationContract]
        string saludar(string nombre);
    }
}

他们的实施如下:

namespace PruebaWCFEndpoint
{
    public class Hola : IHola
    {
        public string saludar(string nombre)
        {
            return "hola" + nombre;
        }
    }
}

0 个答案:

没有答案