ATL_DEV
ATL_DEV

Reputation: 9591

Why is Add Service Reference not generating the same code in UWP?

I am trying to call FedEx's rate service. On their sample app, their reference.cs implements RateService():

amespace RateWebServiceClient.RateServiceWebReference {
using System;
using System.Web.Services;
using System.Diagnostics;
using System.Web.Services.Protocols;
using System.Xml.Serialization;
using System.ComponentModel;


/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "4.6.1038.0")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="RateServiceSoapBinding", Namespace="http://fedex.com/ws/rate/v22")]
public partial class RateService : System.Web.Services.Protocols.SoapHttpClientProtocol {

    private System.Threading.SendOrPostCallback getRatesOperationCompleted;

    private bool useDefaultCredentialsSetExplicitly;

    /// <remarks/>
    public RateService() {
        this.Url = "https://wsbeta.fedex.com:443/web-services/rate";
        if ((this.IsLocalFileSystemWebService(this.Url) == true)) {
            this.UseDefaultCredentials = true;
            this.useDefaultCredentialsSetExplicitly = false;
        }
        else {
            this.useDefaultCredentialsSetExplicitly = true;
        }
    }

When I generate it on my project, I get completely different code. I noticed I never saw the old fashion web services option.

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool. 
//     Runtime Version:4.0.30319.42000
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//---------------------------------------------------------------------------- 
// 
// This code was auto-generated by   Microsoft.VisualStudio.ServiceReference.Platforms, version 15.0.26919.1
// namespace Carriers.FedExServiceReference {   

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://fedex.com/ws/rate/v22", ConfigurationName="FedExServiceReference.RatePortType")]
public interface RatePortType {

    [System.ServiceModel.OperationContractAttribute(Action="http://fedex.com/ws/rate/v22/getRates", ReplyAction="*")]
    [System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
    System.Threading.Tasks.Task<Carriers.FedExServiceReference.getRatesResponse> getRatesAsync(Carriers.FedExServiceReference.getRatesRequest request);
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.2556.0")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://fedex.com/ws/rate/v22")]
public partial class RateRequest : object, System.ComponentModel.INotifyPropertyChanged {

    private WebAuthenticationDetail webAuthenticationDetailField;

    private ClientDetail clientDetailField;

    private TransactionDetail transactionDetailField;

    private VersionId versionField;

    private bool returnTransitAndCommitField;

    private bool returnTransitAndCommitFieldSpecified;

    private CarrierCodeType[] carrierCodesField;

    private ServiceOptionType[] variableOptionsField;

    private ConsolidationKey consolidationKeyField;

    private RequestedShipment requestedShipmentField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=0)]
    public WebAuthenticationDetail WebAuthenticationDetail {
        get {
            return this.webAuthenticationDetailField;
        }
        set {
            this.webAuthenticationDetailField = value;
            this.RaisePropertyChanged("WebAuthenticationDetail");
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=1)]
    public ClientDetail ClientDetail {
        get {
            return this.clientDetailField;
        }
        set {
            this.clientDetailField = value;
            this.RaisePropertyChanged("ClientDetail");
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=2)]
    public TransactionDetail TransactionDetail {
        get {
            return this.transactionDetailField;
        }
        set {
            this.transactionDetailField = value;
            this.RaisePropertyChanged("TransactionDetail");
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=3)]
    public VersionId Version {
        get {
            return this.versionField;
        }
        set {
            this.versionField = value;
            this.RaisePropertyChanged("Version");
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=4)]
    public bool ReturnTransitAndCommit {
        get {
            return this.returnTransitAndCommitField;
        }
        set {
            this.returnTransitAndCommitField = value;
            this.RaisePropertyChanged("ReturnTransitAndCommit");
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlIgnoreAttribute()]
    public bool ReturnTransitAndCommitSpecified {
        get {
            return this.returnTransitAndCommitFieldSpecified;
        }
        set {
            this.returnTransitAndCommitFieldSpecified = value;
            this.RaisePropertyChanged("ReturnTransitAndCommitSpecified");
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("CarrierCodes", Order=5)]
    public CarrierCodeType[] CarrierCodes {
        get {
            return this.carrierCodesField;
        }
        set {
            this.carrierCodesField = value;
            this.RaisePropertyChanged("CarrierCodes");
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("VariableOptions", Order=6)]
    public ServiceOptionType[] VariableOptions {
        get {
            return this.variableOptionsField;
        }
        set {
            this.variableOptionsField = value;
            this.RaisePropertyChanged("VariableOptions");
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=7)]
    public ConsolidationKey ConsolidationKey {
        get {
            return this.consolidationKeyField;
        }
        set {
            this.consolidationKeyField = value;
            this.RaisePropertyChanged("ConsolidationKey");
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=8)]
    public RequestedShipment RequestedShipment {
        get {
            return this.requestedShipmentField;
        }
        set {
            this.requestedShipmentField = value;
            this.RaisePropertyChanged("RequestedShipment");
        }
    }

    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

    protected void RaisePropertyChanged(string propertyName) {
        System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
        if ((propertyChanged != null)) {
            propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        }
    }
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.2556.0")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://fedex.com/ws/rate/v22")]
public partial class WebAuthenticationDetail : object, System.ComponentModel.INotifyPropertyChanged {

    private WebAuthenticationCredential parentCredentialField;

    private WebAuthenticationCredential userCredentialField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=0)]
    public WebAuthenticationCredential ParentCredential {
        get {
            return this.parentCredentialField;
        }
        set {
            this.parentCredentialField = value;
            this.RaisePropertyChanged("ParentCredential");
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=1)]
    public WebAuthenticationCredential UserCredential {
        get {
            return this.userCredentialField;
        }
        set {
            this.userCredentialField = value;
            this.RaisePropertyChanged("UserCredential");
        }
    }

    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

    protected void RaisePropertyChanged(string propertyName) {
        System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
        if ((propertyChanged != null)) {
            propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        }
    }
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.2556.0")]
[System.Diagnostics.DebuggerStepThroughAttribute()]

How do I use this newfangled code? Why the change?

Upvotes: 0

Views: 655

Answers (1)

Sunteen Wu
Sunteen Wu

Reputation: 10627

How do I use this newfangled code?

You could create an instance for the service client (proxy), and invoke the service with it. For example (ToDoService is the namespace you defined for this service client):

ToDoService.RatePortTypeClient client = new ToDoService.RatePortTypeClient(); 

More details about how to you may reference this thread.

Why the change?

The Reference.cs is proxy that auto generated by tools. The sample client app you are downloading is a ConsoleApplication which is target .Net framework 2.0, but your app is a UWP app. They are different applications and target different frameworks. Even you can find the Reference.cs file was auto-generated by Microsoft.VSDesigner in the sample app, but was auto-generated by Microsoft.VisualStudio.ServiceReference.Platforms in your UWP app.

Upvotes: 1

Related Questions