将数据传递给公共部分类C# [英] Pass data to public partial class C#

查看:66
本文介绍了将数据传递给公共部分类C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好在这里。

我通过API发送一些数据有点困难。

我可以通过API C提取数据#没问题,但是当我尝试将数据传递给类没有任何反应。



我尝试了很多不同的调用,但现在已经简化了代码,使其更易于管理。



我想通过API在网站上插入数据(订单)。

我把代码放在后面,我引​​用的是Class至。 *



希望有人能指出我正确的方向。





代码落后



Hello In here .
I'm a little stuck in sending some data via the API.
I can extract data via API C# no problem, but when I try to pass data to a Class nothing happens.

I've tried a lot of different calls , but has now simplified the code so that it is more manageable.

I want to insert data (orders) on a website via the API .
I have put the code behind and the Class I refer to. *

Hope there are someone who can point me in the right direction.


Code behind

WebServiceService objWebService = new WebServiceService();

  protected void btnordercreate_Click(object sender, EventArgs e)
    {
      
  

        objWebService.CookieContainer = new System.Net.CookieContainer();
        objWebService.Solution_Connect("USER", "PASSWORD");
        objWebService.Solution_SetLanguage("DK");

        OrderCreate OrderNew = new OrderCreate();
      
        OrderNew.CurrencyId = 57;

        OrderNew.CustomerComment = "test";
        OrderNew.DeliveryId = 58;
        OrderNew.DeliveryPrice = 1000;

      OrderNew.Origin = "Test";
        OrderNew.PaymentId = 58;

        OrderNew.ReferenceNumber = "29374";

        OrderNew.UserId = 18;
}

The Class

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.33440")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="https://api.smart-web.dk/service.php")]
public partial class OrderCreate {
    
    private int currencyIdField;
    
    private int userIdField;
    
    private bool userIdFieldSpecified;
    
    private int paymentIdField;
    
    private int paymentOnlineIdField;
    
    private bool paymentOnlineIdFieldSpecified;
    
    private string customerCommentField;
    
    private int deliveryIdField;
    
    private double deliveryPriceField;
    
    private bool deliveryPriceFieldSpecified;
    
    private string referenceNumberField;
    
    private OrderLineCreate[] orderLinesField;
    
    private OrderCustomerCreate orderCustomerField;
    
    private OrderTransactionCreate orderTransactionField;
    
    private string originField;
    
    private OrderDelivery deliveryField;
    
    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public int CurrencyId {
        get {
            return this.currencyIdField;
        }
        set {
            this.currencyIdField = value;
        }
    }
    
    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public int UserId {
        get {
            return this.userIdField;
        }
        set {
            this.userIdField = value;
        }
    }
    
    /// <remarks/>
    [System.Xml.Serialization.XmlIgnoreAttribute()]
    public bool UserIdSpecified {
        get {
            return this.userIdFieldSpecified;
        }
        set {
            this.userIdFieldSpecified = value;
        }
    }
    
    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public int PaymentId {
        get {
            return this.paymentIdField;
        }
        set {
            this.paymentIdField = value;
        }
    }
    
    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public int PaymentOnlineId {
        get {
            return this.paymentOnlineIdField;
        }
        set {
            this.paymentOnlineIdField = value;
        }
    }
    
    /// <remarks/>
    [System.Xml.Serialization.XmlIgnoreAttribute()]
    public bool PaymentOnlineIdSpecified {
        get {
            return this.paymentOnlineIdFieldSpecified;
        }
        set {
            this.paymentOnlineIdFieldSpecified = value;
        }
    }
    
    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public string CustomerComment {
        get {
            return this.customerCommentField;
        }
        set {
            this.customerCommentField = value;
        }
    }
    
    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public int DeliveryId {
        get {
            return this.deliveryIdField;
        }
        set {
            this.deliveryIdField = value;
        }
    }
    
    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public double DeliveryPrice {
        get {
            return this.deliveryPriceField;
        }
        set {
            this.deliveryPriceField = value;
        }
    }
    
    /// <remarks/>
    [System.Xml.Serialization.XmlIgnoreAttribute()]
    public bool DeliveryPriceSpecified {
        get {
            return this.deliveryPriceFieldSpecified;
        }
        set {
            this.deliveryPriceFieldSpecified = value;
        }
    }
    
    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public string ReferenceNumber {
        get {
            return this.referenceNumberField;
        }
        set {
            this.referenceNumberField = value;
        }
    }
    
    /// <remarks/>
    [System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    [System.Xml.Serialization.XmlArrayItemAttribute("item", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)]
    public OrderLineCreate[] OrderLines {
        get {
            return this.orderLinesField;
        }
        set {
            this.orderLinesField = value;
        }
    }
    
    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public OrderCustomerCreate OrderCustomer {
        get {
            return this.orderCustomerField;
        }
        set {
            this.orderCustomerField = value;
        }
    }
    
    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public OrderTransactionCreate OrderTransaction {
        get {
            return this.orderTransactionField;
        }
        set {
            this.orderTransactionField = value;
        }
    }
    
    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public string Origin {
        get {
            return this.originField;
        }
        set {
            this.originField = value;
        }
    }
    
    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public OrderDelivery Delivery {
        get {
            return this.deliveryField;
        }
        set {
            this.deliveryField = value;
        }
    }
}

推荐答案

你需要意识到的是这个课程是在客户端创建并运行。实际上,在上面的代码片段中,您实际上并没有调用服务器端会发生的任何事情。所以,你说你有一个API可以调用 - 大概是在那个API上有一个接受你的OrderCreate实现的方法,它可以做你想要的。基本上,当您导入定义时,您创建了一组在服务调用的客户端运行的代理项,这就是您的OrderCreate - 它是代理。此类与服务器端没有实际连接,因此您需要使用接受此调用的方法来完成工作。知道该方法也是一个代理,你可能会感到惊讶;幕后代码负责根据需要编组数据并通过网络将其传输到服务器端。
Something that you have to realise is that the class is created and run on the client side. You haven't actually, in your snippet above, actually invoked anything that would happen on the server side. So, you say you have an API to call - presumably there's a method on that API that accepts your OrderCreate implementation that does what you want. Basically, when you imported your definitions, you created a set of Proxy items that run at the client end of the service call, and that's what your OrderCreate is - it's a proxy. This class has no real connection to the server side, so you need to use the method that accepts this call to do the work. It might surprise you to know that that method will be a proxy as well; the code behind the scenes is responsible for marshalling your data as appropriate and transmitting it over the wire to the server side.


这篇关于将数据传递给公共部分类C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆