Service reference not generating client types

前端 未结 7 937
野性不改
野性不改 2020-12-06 04:13

I am trying to consume a WCF service in a class library by adding a service reference to it. In one of the class libraries it gets consumed properly and I can access the cli

相关标签:
7条回答
  • 2020-12-06 04:40

    Apparently you have to add a reference to System.Web in your project before adding the Service Reference. That did it.

    0 讨论(0)
  • 2020-12-06 04:41

    I'd faced similar issue this is due to type mismatch. Because of which I was not able to generate the client in the test project. We maintain different versions of contracts, while creating new version I'd introduced type mismatch error. Following was the code scenario in my case.

    Version 1 Contract

    [DataContract(Namespace="http://www.exmample.com/v1")]
    public enum Fruits
    {
        [EnumMember]
        Apple,
        [EnumMember]
        Orange
    }
    

    Version 2 Contract

    [DataContract(Namespace="http://www.exmample.com/v1")]
     public enum Fruits
     {
        [EnumMember]
        Apple,
        [EnumMember]
        Orange,
        [EnumMember]
        Mango
     }
    

    I've resolved this issue using svcutil command line utility. Command

    svcutil MyContract.dll
    

    I got the below error message

    DataContract for type 'V2.Fruits' cannot be added to DataContractSet since type 'V1.Fruits with the same data contract name 'Fruits' in namespace 'http://www.exmample.com/v1' is already present and the contracts are not equivalent.
    

    I changed the namespace from version 1 to version 2 and I was able to generate service reference in test project.

    [DataContract(Namespace="http://www.exmample.com/v2")]
     public enum Fruits
     {
        [EnumMember]
        Apple,
        [EnumMember]
        Orange,
        [EnumMember]
        Mango
     }
    

    Make use of svcutil this will help to resolve this issue.

    0 讨论(0)
  • 2020-12-06 04:46

    I encountered the same issue. Turns out my project was referencing a DLL directly instead of a project reference. So even though my project had a reference for the assembly, it was to an old version. Once I updated the DLL and updated the service reference everything was working again.

    0 讨论(0)
  • 2020-12-06 04:46

    Along the lines of @Kevin's answer, I added references to all the projects and DLLs referenced in the service project. The proxy generation was then able to recognise / generate the types required.

    Once that's done, you could even then start to remove some and regenerate to exclude the redundant ones.

    0 讨论(0)
  • 2020-12-06 04:54

    The real answer is, if you are serializing a type using the KnownTypeAttribute on your service contract, you MUST include a reference to your type's library in the project you are adding the service reference to.

    For example, if your wcf service serializes the type System.Drawing.Image, then the consumer project MUST have a reference to System.Drawing. Hope this helps some folks out there.

    0 讨论(0)
  • 2020-12-06 04:54

    This normally happens for adding a service reference that you had added before. In the client config, it still has the relevant servicemodel. Make sure you delete the servicemodel from the client config and then try to re-add the service reference again!

    0 讨论(0)
提交回复
热议问题