2

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?

Alex
  • 7,639
  • 3
  • 45
  • 58
  • Your class did not use [DataContract] attribute. – Aslam Jiffry Aug 06 '15 at 10:02
  • @AslamJiffry as I already commented on your answer before it was deleted - [`DataContract` is not necessary](http://stackoverflow.com/a/4836803/1860652). That's not the issue. – Alex Aug 06 '15 at 10:05
  • I deleted it purposefully . It is not suitable as an answer. It should be in comment . Thanks. – Aslam Jiffry Aug 06 '15 at 10:07
  • Does the message you posted was captured with wcf trace log? Just a comment about DataContract: the link you've posted has great information about, but I prefer to get information on the own Microsoft posts, and there (https://msdn.microsoft.com/en-us/library/ms733127(v=vs.110).aspx) says: "primitive types .... are considered as having default data contracts." "New complex types that you create must have a data contract defined for them to be serializable" like your PremiumContent class. Any way, this is not the point here, I've tested your code as it is and worked here. – Ricardo Pontual Aug 06 '15 at 11:29
  • @RicardoPontual thanks for the link. Yes, the message was captured using [WCF Message Logging](https://msdn.microsoft.com/en-us/library/ms731859(v=vs.110).aspx) – Alex Aug 06 '15 at 11:40
  • I could test a simple wcf with your code and it worked fine. Actually it's a very simple contract, it could not have any problems. The only difference I could notice between our soap requests was namespaces (off course) and the encoding header tag. I turned on the trace for messages and logs and I got an error between "Content Type application/soap+xml; charset=utf-8 but expected text/xml; charset=utf-8" – Ricardo Pontual Aug 06 '15 at 13:26
  • Actually I don't think the encoding can cause this, but it's a point to check out – Ricardo Pontual Aug 06 '15 at 13:41

1 Answers1

0

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.

Alex
  • 7,639
  • 3
  • 45
  • 58