WCF - Update Service References from CLI
Asked Answered
C

1

1

I'm currently working on a project where we have some WCF services and a REST API calling those WCF services. Everything is in .Net Framework 4.7.2.

When a method signature is updated, a DTO or an Enum is changed in one of the services, we Update the Service References to make the REST API Project aware of those changes. We currently do that with Visual Studio 2019 Professional, with the Update Service References button. This button is under :

The project -> Service References -> Select all contracts -> Right click -> Update Service References.

This is a manual task that we want to automate because it's quite time consuming.

I've searched on the internet and found this and this but nothing very convincing.

When doing the manual task, we end up with this :

Service References
├───ApcDossierContract
│       ApcDossierService.xsd
│       ApcDossierService1.disco
│       ApcDossierService1.wsdl
│       ApcDossierService1.xsd
│       ApcDossierService6.xsd
│       ApcDossierService61.xsd
│       ApcDossierService62.xsd
│       ApcDossierService63.xsd
│       ApcDossierService64.xsd
│       ApcDossierService65.xsd
│       configuration.svcinfo
│       configuration91.svcinfo
│       Reference.cs
│       Reference.svcmap
├───ClientContract
.
.
.

The most important file is the Reference.cs which look like this :


namespace DummyNamespace.Move.BackEnd.ApcDossierContract {
    
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    [System.ServiceModel.ServiceContractAttribute(ConfigurationName="ApcDossierContract.IApcDossierService")]
    public interface IApcDossierService {
        
        [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IPingService/HealthStatus", ReplyAction="http://tempuri.org/IPingService/HealthStatusResponse")]
        DummyNamespace.Services.Common.ResultWcf<string[]> HealthStatus();
        
        ...    
    }
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    public interface IApcDossierServiceChannel : DummyNamespace.Move.BackEnd.ApcDossierContract.IApcDossierService, System.ServiceModel.IClientChannel {
    }
    
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    public partial class ApcDossierServiceClient : System.ServiceModel.ClientBase<DummyNamespace.Move.BackEnd.ApcDossierContract.IApcDossierService>, DummyNamespace.Move.BackEnd.ApcDossierContract.IApcDossierService {
      
        public DummyNamespace.Services.Common.ResultWcf<string[]> HealthStatus() {
            return base.Channel.HealthStatus();
        }
 
        ...
    }
}

When using svcutil.exe (C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\Bin\NETFX 4.8 Tools\svcutil.exe), I don't get all the XSD, svcinfo and svcmap files. The Reference.cs is much bigger because custom types aren't used, for example ResultWcf.

I've also tried using the newer version of svcutil (here)[https://github.com/dotnet/docs/blob/main/docs/core/additional-tools/dotnet-svcutil-guide.md] by doing :

dotnet tool install --global dotnet-svcutil

But the result was the same.

If anyone has already created a script to automate this task, it will be welcomed, thanks for your time !

Congeal answered 8/3, 2023 at 10:54 Comment(0)
C
1

Svcutil is still needed to update the wcf service reference, and command line or PowerShell is needed for automation.

You can use some help commands dotnet-svcutil --help to get help. If your project files are not in the same place, specify the location of the service reference dotnet svcutil -u. \path\to\ServiceReference. The easiest way to do this is to update it like this dotnet-svcutil -u ServiceReference.

Cortezcortical answered 9/3, 2023 at 6:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.