简体   繁体   中英

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

I'm trying to build a webservice client and access a webservice using #C in Visual Studio, but I have some broblems making use of the proxy classes created from the webservice.

I'm trying to access a method in a proxy class and display the values returned by the method on a web page.

This is the class and the method I'm trying to access is 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));
        }
    }
}

On WebForm1.aspx.cs I have this content:

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

        }
    }
}

This method will return a race day and I'm trying to display it on WebForm1.aspx. First I tried with:

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

Then "pbs.fetchRaceDayCalendarSimple().raceDay;" is underlined so I understand that something is wrong. When hovering over it I get the error message:

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

So I figure I should do this instead:

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

So "test" is the div id on the page WebForm1.aspx:

<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>

So then when loading WebForm1.aspx this is what is displayed:

Test:
WebServiceClient.InformationServiceReference.RaceDaySimple[]

Only the name of the method is displayed, but I want the method to displayed what the method does and that is to display a race day. So how do I do that?

The error is saying you are getting a list of RaceDaySimple not one item. So try using the first item in the list

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM