为什么添加服务引用不在UWP中生成相同的代码?

时间:2017-10-27 22:22:27

标签: web-services wcf uwp

我正在尝试拨打联邦快递的费率服务。在他们的示例应用程序中,他们的reference.cs实现了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;
        }
    }

当我在项目中生成它时,我会得到完全不同的代码。我注意到我从未见过旧的时尚网络服务选项。

//------------------------------------------------------------------------------
// <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()]

如何使用这个新奇的代码?为什么要改变?

1 个答案:

答案 0 :(得分:0)

  

如何使用这个新奇的代码?

您可以为服务客户端(代理)创建一个实例,并使用它来调用服务。例如(ToDoService是您为此服务客户端定义的命名空间):

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

有关您如何参考的详细信息,请参阅this thread

  

为什么要改变?

Reference.cs是由工具自动生成的代理。您下载的示例客户端应用是ConsoleApplication目标.Net framework 2.0,但您的应用是UWP应用。它们是不同的应用程序,并针对不同的框架。即使您可以在示例应用中找到由Reference.cs自动生成的Microsoft.VSDesigner文件,但是在您的UWP应用中由Microsoft.VisualStudio.ServiceReference.Platforms自动生成。