Search code examples
c#wcfvisual-studio-2012datacontract

One of the DataContract classes doesn't generating on the client side by adding service reference


I have three DataContract classes in wcf service. I've added service reference to the client and two of my classes work great, but the third one hasn't appeared in service reference. I don't use this class in my service interface, can it be the reason of my problem? Here is this class:

[DataContract]
public class Security
{
    public Security(){ }

    public string Sha1(string input)
    {
        byte[] hash;
        using (SHA1CryptoServiceProvider Sha1Provider = new SHA1CryptoServiceProvider())
        {
            hash = Sha1Provider.ComputeHash(Encoding.Unicode.GetBytes(input));
        }
        var sb = new StringBuilder();
        foreach (byte b in hash) sb.AppendFormat("{0:x2}", b);
        return sb.ToString();
    }
}

If it is important, I've added reference for System.Security.Cryptography to my client.


Solution

  • If the DataContract is not exposed in your ServiceContract, the client won't get the DataContract because it isn't needed.

    A more robust explanation can be found on this question: DataContract not available at WCF client service reference