WCF Rest.svc causes an error while directly viewing, but works differently

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

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

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

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

System.InvalidOperationException: The exception was caused by a WSDL export extension call: System.ServiceModel.Description.DataContractSerializerOperationBehavior contract: http://tempuri.org/:IRest ----> System.InvalidOperationException: the AddFile operation 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 other types of parameters.

I understand the error, but wondered how to fix / suppress it so that it displays the default WCF endpoint page. I just use WCF for REST only.

Thanks!

Jeffrey Kevin Pry

+4
source share
2 answers

This is a problem when the WSDL mechanism tries to generate a description for your service, and it is incapable because the service contract that you defined usually does not work for the RPC-style endpoints for which the WSDL engine is being processed. This is why you get an error message that you see that the message cannot be mixed with typed parameters. You must configure the service with <serviceMetadata httpGetEnabled="false" /> , because WSDL and REST just don't play together.

If you expect any other β€œhelp” page for a REST service, maybe you are thinking of <serviceDebug httpHelpPageEnabled="true" /> ?

+6
source

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

+1
source

All Articles