簡體   English   中英

訪問代理類中的方法(使用Visual Studio中的Web服務,C#)

[英]Access a method in a proxy class (using webservice in Visual Studio, C#)

我正在嘗試構建Web服務客戶端,並在Visual Studio中使用#C訪問Web服務,但是我有一些利用從Web服務創建的代理類的問題。

我正在嘗試訪問代理類中的方法,並在網頁上顯示該方法返回的值。

這是此類,我嘗試訪問的方法是RaceDaySimple [] raceDay:

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.18408")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="java:se.atg.aisbean.calendar")]
public partial class RaceDayCalendarSimple : object, System.ComponentModel.INotifyPropertyChanged {

    private RaceDaySimple[] raceDayField;

    private AtgDateTime timestampField;

    /// <remarks/>
    [System.Xml.Serialization.XmlArrayAttribute(IsNullable=true, Order=0)]
    /*Access this method ==>*/public RaceDaySimple[] raceDay {
        get {
            return this.raceDayField;
        }
        set {
            this.raceDayField = value;
            this.RaisePropertyChanged("raceDay");
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(IsNullable=true, Order=1)]
    public AtgDateTime timestamp {
        get {
            return this.timestampField;
        }
        set {
            this.timestampField = value;
            this.RaisePropertyChanged("timestamp");
        }
    }

    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));
        }
    }
}

在WebForm1.aspx.cs上,我具有以下內容:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebServiceClient
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            InformationServiceReference.PartnerInfoServicePortClient pbs = new InformationServiceReference.PartnerInfoServicePortClient();
            pbs.ClientCredentials.UserName.UserName = "SomeUsername";
            pbs.ClientCredentials.UserName.Password = "SomePassword";

            test.InnerHtml = Convert.ToString(pbs.fetchRaceDayCalendarSimple().raceDay);

        }
    }
}

此方法將返回比賽日,我正在嘗試在WebForm1.aspx上顯示它。 首先,我嘗試了:

test.InnerHtml = pbs.fetchRaceDayCalendarSimple().raceDay;

然后是“ pbs.fetchRaceDayCalendarSimple()。raceDay;” 帶下划線,因此我知道有些問題。 將鼠標懸停在它上面時,會顯示錯誤消息:

Cannot implicitly convert 'WebServiceClient.InformationServiceReference.RaceDaySimple[]' to 'String'

所以我想我應該這樣做:

test.InnerHtml = Convert.ToString(pbs.fetchRaceDayCalendarSimple().raceDay);

因此,“ test”是WebForm1.aspx頁面上的div ID:

<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <h1>Test:</h1>
                <div id="test" runat="server"></div>
            </div>
        </form>
    </body>
</html>

因此,當加載WebForm1.aspx時,將顯示以下內容:

測試:
WebServiceClient.InformationServiceReference.RaceDaySimple []

僅顯示方法的名稱,但我希望該方法顯示該方法的作用,即顯示比賽日。 那我該怎么做呢?

錯誤是說您得到的是RaceDaySimple列表而不是一項。 因此,請嘗試使用列表中的第一項

test.InnerHtml = pbs.fetchRaceDayCalendarSimple().FirstOrDefault().raceDay;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM