MVC应用程序中基于MessageContract的WCF服务将不提供元数据

|| 我一直在阅读关于SO的所有问题,我可以在MVC应用程序中托管WCF服务时发现这些问题,但是不幸的是,我没有找到许多有关指定“ 0”的服务的信息。我需要进行流文件传输,因此,如果我想接受有关流的元数据,则必须在消息协定中指定标头。 我已将此服务添加到我的MVC应用中,并添加了“ѭ1”;浏览器无法按预期获取WSDL,而Visual Studio无法获取生成客户端代理类所需的服务元数据。两者都收到如下错误:
Operation \'ImportMessageBody\' in contract \'IImport\' uses a MessageContract that has 
SOAP headers. SOAP headers are not supported by the None MessageVersion.
关联的堆栈跟踪:
[InvalidOperationException: Operation \'ImportMessageBody\' in contract \'IImport\' uses a MessageContract that has SOAP headers. SOAP headers are not supported by the None MessageVersion.]
   System.ServiceModel.Description.WebHttpBehavior.ValidateNoMessageContractHeaders(MessageDescription md, String opName, String contractName) +704271
   System.ServiceModel.Description.WebHttpBehavior.ValidateContract(ServiceEndpoint endpoint) +134
   System.ServiceModel.Description.WebHttpBehavior.Validate(ServiceEndpoint endpoint) +51
   System.ServiceModel.Description.ServiceEndpoint.Validate(Boolean runOperationValidators, Boolean isForService) +287
   System.ServiceModel.Description.DispatcherBuilder.ValidateDescription(ServiceDescription description, ServiceHostBase serviceHost) +271
   System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost) +109
   System.ServiceModel.ServiceHostBase.InitializeRuntime() +60
   System.ServiceModel.ServiceHostBase.OnBeginOpen() +27
   System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) +50
   System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +318
   System.ServiceModel.Channels.CommunicationObject.Open() +36
   System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +184
   System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +615

[ServiceActivationException: The service \'/a/import\' cannot be activated due to an exception during compilation.  The exception message is: Operation \'ImportMessageBody\' in contract \'IImport\' uses a MessageContract that has SOAP headers. SOAP headers are not supported by the None MessageVersion..]
   System.Runtime.AsyncResult.End(IAsyncResult result) +679246
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +190
   System.ServiceModel.Activation.AspNetRouteServiceHttpHandler.EndProcessRequest(IAsyncResult result) +6
   System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +96
WcfTestClient也有同样的问题(正如我所期望的)。 我需要做什么才能启用客户端代理生成? 这是我的MVC应用程序的web.config文件的serviceModel部分:
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name=\"\">
          <serviceMetadata httpGetEnabled=\"true\" />
          <serviceDebug includeExceptionDetailInFaults=\"true\" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled=\"true\" aspNetCompatibilityEnabled=\"true\" />
  </system.serviceModel>
我添加的路线:
public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute(\"{resource}.axd/{*pathInfo}\");
            routes.IgnoreRoute(\"{resource}.svc/{*pathInfo}\");
            routes.IgnoreRoute(\"favicon.ico\");

            routes.Add(new ServiceRoute(\"a/import\", new WebServiceHostFactory(), typeof(Services.Import.Import)));
            routes.MapRoute(
                \"Default\", // Route name
                \"{controller}/{action}/{id}\", // URL with parameters
                new { controller = \"Home\", action = \"Index\", id = UrlParameter.Optional } // Parameter defaults
            );
        }
    
已邀请:
        您通过WebServiceHostFactory托管服务,这意味着您正在创建REST端点。 MessageContract的目的是定义SOAP消息(标头和正文),因此,使用WebServiceHostFactory创建的服务不支持它们。 您是否要使用SOAP端点而不是REST端点?     

要回复问题请先登录注册