SOAP headers in WCF REST error

I have this error:

The GetFields operation in the IService contract uses a MessageContract with SOAP headers. SOAP headers are not supported by any MessageVersion.

The problem is that my operation was used by two endpoints: CustomEndpoint with messageVersion = "Soap12WSAddressing10" and the second webHttpBehavior.

And I think this problem is with a fire error that Rest has MessageVersion.None

How to fix it?

+4
source share
3 answers

Unfortunately, in WCF, RESTfulness tends to be a contract level function. This means that you often cannot use a RESTful contract in a context other than RESTful, and vice versa.

You have two options, and each has its own compromises. First, you can have two separate contracts (one of them is marked for RESTful and "simple" rather than RESTful functions), which are both implemented by your WCF service. This requires that both contracts have identical method signatures, which is not always possible.

The second option is to have two separate WCF services, each of which has its own contract and processing code, but so that they both upload the operation calls to the third class, they both know what the actual work does. This is the most flexible solution, but calling a third class requires a special translation code in (or both) the WCF service.

+2
source

You do not need to provide another interface and / or implement a class of service.

IF you use code in the behavior that XXMessageHeaders tries to use through OperationContext, you need to write code to check if MessageVersion is in MessageVersion.None headers and WebOperationContext is used instead (from System.ServiceModel.Web).

I have a working example with the same interface and with the same implementation class.

<services> <service name="ExampleService" behaviorConfiguration="MyServiceBehavior"> <endpoint name="ExampleService.BasicHttpBinding" binding="basicHttpBinding" contract="IExampleService" address="" /> <endpoint name="ExampleService.WebHttpBinding" binding="webHttpBinding" contract="IExampleService" address="restful" behaviorConfiguration="webHttpRestulBehavior" /> </service> </services> <behaviors> <endpointBehaviors> <behavior name="webHttpRestulBehavior"> <webHttp/> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name="MyServiceBehavior"> <serviceDebug includeExceptionDetailInFaults="true"/> <serviceMetadata httpGetEnabled="true" /> </behavior> </serviceBehaviors> </behaviors> 

Assuming .svc is an example of .svc

In IIS, the final URL will be:

"HTTP: // hostname: port /Example.svc"

for WCF

for relax:

"HTTP: // hostname: port / Example.svc / sedative /"

+1
source

I experienced the same exception as when trying to combine the two services; which used the SOAP endpoint and the other the REST endpoint.

I think the problem is that WCF does not seem to see operations that use MessageContract in the same ServiceContract as a REST operation. So the way I got around was to split the contracts into two parts, and then the REST endpoint only performed the WebGet operation as follows:

 [ServiceContract] public interface IExampleSoapService : IExampleRestService { [OperationContract] void SomeSoapOperation(ExampleMessageContract message); } [ServiceContract] public interface IExampleRestService { [OperationContract] [WebGet(UriTemplate = "/{id}", RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare)] void SomeRestOperation(int id); } 

And then in the configuration:

 <services> <service name="ExampleService"> <endpoint name="ExampleService.BasicHttpBinding" binding="basicHttpBinding" contract="IExampleSoapService" address="soap" /> <endpoint name="ExampleService.WebHttpBinding" binding="webHttpBinding" contract="IExampleRestService" /> </service> </services> 

One I divided the contracts as follows, the problem seems to go away.

0
source

Source: https://habr.com/ru/post/1379337/


All Articles