Service reference not generating client types

2019-01-18 08:52发布

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 client types in order to generate a proxy off of them. However in my second class library (or even in a console test app), when i add the same service reference, it only exposes the types that are involved in the contract operations and not the client type for me to generate a proxy against.

e.g. Endpoint has 2 services exposed - ISvc1 and ISvc2. When I add a service reference to this endpoint in the first class library I get ISvc1Client andf ISvc2Client to generate proxies off of in order to use the operations exposed via those 2 contracts. In addition to these clients the service reference also exposes the types involved in the operations like (type 1, type 2 etc.) this is what I need. However when i try to add a service reference to the same endpoing in another console application or class library only Type 1, Type 2 etc. are exposed and not ISvc1Client and ISvc2Client because of which I cannot generate a proxy to access the operations I need. I am unable to determine why the service reference gets properly generated in one class library but not in the other or the test console app.

7条回答
疯言疯语
2楼-- · 2019-01-18 09:49

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.

查看更多
登录 后发表回答