Alex
Alex

Reputation: 7919

Why is my WCF service ignoring items in an array parameter?

My WCF service suddenly stopped working correctly a few days ago, seemingly without either the client or server having been touched. Specifically it is a single operation that is not working correctly because one of the parameters is an array, which never gets populated by WCF.

I've observed this in both production and my own dev environment. When I debug the outgoing client method, the array has a single item but the incoming service method receives an empty array.

The interface of the service looks like this:

[ServiceContract]
public interface IMembershipService
{
    [OperationContract]
    Boolean ActivateAllPremiumContent(Int32 memberId, PremiumContent[] premiumContentIds);
}

public class PremiumContent
{
    public Int32 Id { get; set; }
    public String Name { get; set; }
    public DateTime? Expiry { get; set; }
    public Boolean HasAccess { get; set; }
}

I've got as far as logging the incoming SOAP message, which proves that the data is present when the service receives the message (the HasAccess and Name parameters are not populated by the client - they haven't been lost):

<MessageLogTraceRecord>
    <HttpRequest xmlns="http://schemas.microsoft.com/2004/06/ServiceModel/Management/MessageTrace">
        <Method>POST</Method>
        <QueryString></QueryString>
        <WebHeaders>
            <Content-Length>500</Content-Length>
            <Content-Type>text/xml; charset=utf-8</Content-Type>
            <Accept-Encoding>gzip, deflate</Accept-Encoding>
            <Expect>100-continue</Expect>
            <Host>local.redacted.com</Host>
            <SOAPAction>"http://tempuri.org/IMembershipService/ActivateAllPremiumContent"</SOAPAction>
        </WebHeaders>
    </HttpRequest>
    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
        <s:Header>
            <To s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://local.redacted.com/webservices/membership/membershipservice.svc</To>
            <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/IMembershipService/ActivateAllPremiumContent</Action>
        </s:Header>
        <s:Body>
            <ActivateAllPremiumContent xmlns="http://tempuri.org/">
                <memberId>112415</memberId>
                <premiumContentIds xmlns:a="http://schemas.datacontract.org/2004/07/Models" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
                    <a:PremiumContent>
                        <a:Expiry>2015-09-06T09:38:15.54</a:Expiry>
                        <a:HasAccess>false</a:HasAccess>
                        <a:Id>4</a:Id>
                        <a:Name i:nil="true"></a:Name>
                    </a:PremiumContent>
                </premiumContentIds>
            </ActivateAllPremiumContent>
        </s:Body>
    </s:Envelope>
</MessageLogTraceRecord>

Somewhere between this SOAP message being received, and WCF translating it into a function call, the premiumContentIds array loses its content. The memberId parameter is correctly passed, though.

What on earth is going on?

Upvotes: 2

Views: 847

Answers (1)

Alex
Alex

Reputation: 7919

Well, it's not possible to see from my code sample but it turns out my colleague changed the namespace of the PremiumContent class a few months ago. I guess there was some kind of caching going on because that change was released last month, but only started causing problems three days ago when a hotfix was made. Updating the service reference fixed the problem.

I'm not sure if this question is helpful enough to warrant keeping, as it's so specific - but I'll leave it up in case it does prompt someone to check these things.

Upvotes: 0

Related Questions