ServiceHost Error

Damir Dobric Posts

Next talks:

 

    

Follow me on Twitter: #ddobric



 

 

Archives

Problem Description

Operation "xxx" of contract 'yyyy' specifies multiple request body parameters to be serialized without any wrapper elements. At most one body parameter can be serialized without wrapper elements. Either remove the extra body parameters or set the BodyStyle property on the WebGetAttribute/WebInvokeAttribute to Wrapped.

 

Solution

This error occurs while starting of the web service host:

1)  explicitly in the custom host:
    WebServiceHost xmlHost = new WebServiceHost(. . .) or

2)  implicitly by using of SVC-file in IIS host:

     <%@ ServiceHost Language="C#" Debug="true" Service=". . ."
                Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>

The problem is caused by using of the usual service contract, which is styled for standard SOAP-Host (ServiceHost) and not as expected for the WebServiceHost.

This is an example of the contract which cause this error:

[OperationContract]
Airport[] GetCoordinates(string area, int numOfRecords);

To fix it, use REST-specific styling of the operation as shown below, or use ServiceHost instead of WebServiceHost.

[OperationContract]
[WebGet(BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json)]
Airport[] GetCoordinates(string area, int numOfRecords);

or

<%@ ServiceHost Language="C#" Debug="true" Service=". . ." %>


Posted Dec 26 2008, 11:31 PM by Damir Dobric
Filed under:
developers.de is a .Net Community Blog powered by daenet GmbH.