开发者

MessageContract-based WCF service in MVC app won't serve up metadata

I've been reading through all the questions on SO I could find on hosting a WCF service in a MVC app, and unfortunately I haven't found much information about services which specify MessageContracts. I need to do streaming file transfer, so if I want to accept metadata about the stream, I have to specify headers in the message contract.

I've added this service to my MVC app and added a ServiceRoute; the browser fails to get the WSDL as expected, and Visual Studio fails to get the service metadata required to generate client proxy classes. Both receive an error like the following:

Operation 'ImportMessageBody' in contract 'IImport' uses a MessageContract that has 
SOAP headers. SOAP headers are not supported by the None MessageVersion.

The associated stack trace:

[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 also has the same problem (as I would expect).

What do I need to do to开发者_如何转开发 enable client proxy generation?

Here is the serviceModel section of the web.config file for my MVC app:

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
  </system.serviceModel>

And the route I added:

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


You are hosting the service via WebServiceHostFactory this means you are creating a REST endpoint.

MessageContract's purpose is to define a SOAP message (headers and body) therefore they are not supported for services created with the WebServiceHostFactory

Did you mean to use a SOAP endpoint rather than a REST one?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜