سؤال

I have a WCF rest service with two OperationContracts as follows:

    [OperationContract]
    [WebGet(UriTemplate = "ping/")]
    Message PingServer();

    [OperationContract]
    [WebGet(UriTemplate = "files/")]
    Message AddFile(string accessKey);

When I visit http://localhost/rest.svc/ping/ it works fine and if I visit http://localhost/rest.svc/files/ it works fine.

However, if I visit http://localhost/rest.svc directly, it throws the following error:

System.InvalidOperationException: An exception was thrown in a call to a WSDL export extension: System.ServiceModel.Description.DataContractSerializerOperationBehavior contract: http://tempuri.org/:IRest ----> System.InvalidOperationException: The operation 'AddFile' could not be loaded because it has a parameter or return type of type System.ServiceModel.Channels.Message or a type that has MessageContractAttribute and other parameters of different types. When using System.ServiceModel.Channels.Message or types with MessageContractAttribute, the method must not use any other types of parameters.

I understand the error, but was wondering how to fix/suppress it so it shows the default WCF endpoint page. I am just using WCF for REST only.

Thanks!

Jeffrey Kevin Pry

هل كانت مفيدة؟

المحلول

This is a problem where the WSDL engine is attempting to generate a description for your service and it's unable to because the service contract you've defined wouldn't normally work for RPC style endpoints which the WSDL engine is made to process. This is why you get the error you're seeing about Message not being able to be mixed with typed parameters. You should configure the service with <serviceMetadata httpGetEnabled="false" /> because WSDL and REST just don't play together.

If you are expecting any other kind of "help" page for a REST service perhaps you're thinking of the <serviceDebug httpHelpPageEnabled="true" />?

نصائح أخرى

You can suppress the default "help" page by setting the HttpHelpPageEnabled (and HttpsHelpPageEnabled if applicable) properties to false in the ServiceDebugBehavior. Or in config, set those properties in the <serviceBehaviors/behavior/serviceDebug> element.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top