1
votes

WCF. Framework 4.5.1

Existing web service uses DataContractSerializer.

It now needs to provide a contract that takes XMLSerialized data from a third party as an input parameter and return a serialized object.

Apparently I should be able to decorate that contract with [XMLSerializerFormat]. But this breaks the published site. i.e. You can't even access the site with a web browser to obtain the wsdl.

Is there some extra work needed in the Web.Config?

  [OperationContract]
        [XmlSerializerFormat]
        [WebInvoke(UriTemplate = "", Method = "POST")]
        ResponseMessage Update(RequestMessage instance); 

The contract is sitting inside an interface with all of the existing contracts The interface is decorated

[ServiceContract]
public interface IMyService
{

Thanks Bob

1

1 Answers

0
votes

Problem was that the contract was not specifically decorated with xml. Apparently the default assumption is JSON. Working declaration:

 [OperationContract]
    [XmlSerializerFormat]
    [WebInvoke(UriTemplate = "Update", Method = "POST",
        ResponseFormat = WebMessageFormat.Xml,
        RequestFormat = WebMessageFormat.Xml)]
    ResponseMessage Update(RequestMessage instance);

The 'Answer' I put up has exposed some very strange behavior.

With the [XMLSerializer] decoration in place, other contracts can no longer deserialize integers. The integer property leaves the client as say 6 and is deserialized as 0. Comment out the decoration and normal behavior resumes. I will post a separate question about this.