Quantcast
Channel: WCF, ASMX and other Web Services
Viewing all articles
Browse latest Browse all 555

Bind SOAP response to Gridview using proxy code (request for sample code)

$
0
0

Being a junior ASP Net developer I would like to bind the SOAP response from a web service in ASP Net C# to a gridview via the web proxy.

Following SOAP response:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<GetQueueStatsResponse xmlns="http://www.tix.nl/CtiWebService">
<GetQueueStatsResult xmlns:a="http://schemas.datacontract.org/2004/07/Cti.WebServices" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:QueueInfo>
<a:Name>IP Office Phone: 4201</a:Name>
<a:Statistics>
<a:QueueStat>
<a:AverageWaitTime>0</a:AverageWaitTime>
<a:CallCount>0</a:CallCount>
</a:QueueStat>
<a:QueueStat>
<a:AverageWaitTime>0</a:AverageWaitTime>
<a:CallCount>0</a:CallCount>
</a:QueueStat>
<a:QueueStat>
<a:AverageWaitTime>20</a:AverageWaitTime>
<a:CallCount>2</a:CallCount>
</a:QueueStat>
<a:QueueStat>
<a:AverageWaitTime>14</a:AverageWaitTime>
<a:CallCount>4</a:CallCount>
</a:QueueStat>
<a:QueueStat>
<a:AverageWaitTime>81</a:AverageWaitTime>
<a:CallCount>22</a:CallCount>
</a:QueueStat>
</a:Statistics>
<a:WaitingCalls>
<a:WaitingCall>
<a:CallStart>2018-06-06T16:17:52.3621524+02:00</a:CallStart>
<a:CalledID>4201</a:CalledID>
<a:CallerID>3939</a:CallerID>
</a:WaitingCall>
<a:WaitingCall>
<a:CallStart>2018-06-06T16:19:12.734228+02:00</a:CallStart>
<a:CalledID>4201</a:CalledID>
<a:CallerID>0356991500</a:CallerID>
</a:WaitingCall>
</a:WaitingCalls>
</a:QueueInfo>
<a:QueueInfo>
<a:Name>IP Office Phone: 4202</a:Name>
<a:Statistics>
<a:QueueStat>
<a:AverageWaitTime>0</a:AverageWaitTime>
<a:CallCount>0</a:CallCount>
</a:QueueStat>
<a:QueueStat>
<a:AverageWaitTime>0</a:AverageWaitTime>
<a:CallCount>0</a:CallCount>
</a:QueueStat>
<a:QueueStat>
<a:AverageWaitTime>0</a:AverageWaitTime>
<a:CallCount>0</a:CallCount>
</a:QueueStat>
<a:QueueStat>
<a:AverageWaitTime>0</a:AverageWaitTime>
<a:CallCount>0</a:CallCount>
</a:QueueStat>
<a:QueueStat>
<a:AverageWaitTime>118</a:AverageWaitTime>
<a:CallCount>3</a:CallCount>
</a:QueueStat>
</a:Statistics>
<a:WaitingCalls/>
</a:QueueInfo>
<a:QueueInfo>
<a:Name>IP Office Phone: 4204</a:Name>
<a:Statistics>
<a:QueueStat>
<a:AverageWaitTime>0</a:AverageWaitTime>
<a:CallCount>0</a:CallCount>
</a:QueueStat>
<a:QueueStat>
<a:AverageWaitTime>0</a:AverageWaitTime>
<a:CallCount>0</a:CallCount>
</a:QueueStat>
<a:QueueStat>
<a:AverageWaitTime>0</a:AverageWaitTime>
<a:CallCount>0</a:CallCount>
</a:QueueStat>
<a:QueueStat>
<a:AverageWaitTime>0</a:AverageWaitTime>
<a:CallCount>0</a:CallCount>
</a:QueueStat>
<a:QueueStat>
<a:AverageWaitTime>38</a:AverageWaitTime>
<a:CallCount>13</a:CallCount>
</a:QueueStat>
</a:Statistics>
<a:WaitingCalls/>
</a:QueueInfo>
</GetQueueStatsResult>
</GetQueueStatsResponse>
</s:Body>
</s:Envelope>

Following Web Application I am able only to bind the Name field to the gridview, do you have some sample code to loop through the SOAP response elements,

namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
public object XMLReader { get; private set; }

protected void Page_Load(object sender, EventArgs e)
{

using (var proxy = new WebApplication1.ServiceReference2.CtiWebServiceClient())
{
ServiceReference2.QueueInfo[] data = proxy.GetQueueStats();
GridView1.DataSource = data;
GridView1.DataBind();


For example how to loop through the elements, access the element AverageWaitTime, how to do a count of the number of waiting calls using the proxy code (XML code below is working)? Thank you in advance for your response.

document.Load(Server.MapPath("~/xmlstart/test.xml"));
XmlNamespaceManager manager = new XmlNamespaceManager(document.NameTable);
manager.AddNamespace("a", "http://schemas.datacontract.org/2004/07/Cti.WebServices");
XmlNodeList xnList = document.SelectNodes("//a:QueueStat", manager);
int nodes = xnList.Count;
foreach (XmlNode xn in xnList)
{
AverageWaitTime.Text += xn["a:AverageWaitTime"].InnerText + "<br />";
CallCount.Text += xn["a:CallCount"].InnerText + "<br />";
}

LabelWaitingCallCountHuntgroep1.Text = nodes2.ToString();

Web Reference code is as follows:
//------------------------------------------------------------------------------
// <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>
//------------------------------------------------------------------------------

namespace WebApplication1.ServiceReference2 {
using System.Runtime.Serialization;
using System;


[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="QueueInfo", Namespace="http://schemas.datacontract.org/2004/07/Cti.WebServices")]
[System.SerializableAttribute()]
public partial class QueueInfo : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {

[System.NonSerializedAttribute()]
private System.Runtime.Serialization.ExtensionDataObject extensionDataField;

[System.Runtime.Serialization.OptionalFieldAttribute()]
private string NameField;

[System.Runtime.Serialization.OptionalFieldAttribute()]
private WebApplication1.ServiceReference2.QueueStat[] StatisticsField;

[System.Runtime.Serialization.OptionalFieldAttribute()]
private WebApplication1.ServiceReference2.WaitingCall[] WaitingCallsField;

[global::System.ComponentModel.BrowsableAttribute(false)]
public System.Runtime.Serialization.ExtensionDataObject ExtensionData {
get {
return this.extensionDataField;
}
set {
this.extensionDataField = value;
}
}

[System.Runtime.Serialization.DataMemberAttribute()]
public string Name {
get {
return this.NameField;
}
set {
if ((object.ReferenceEquals(this.NameField, value) != true)) {
this.NameField = value;
this.RaisePropertyChanged("Name");
}
}
}

[System.Runtime.Serialization.DataMemberAttribute()]
public WebApplication1.ServiceReference2.QueueStat[] Statistics {
get {
return this.StatisticsField;
}
set {
if ((object.ReferenceEquals(this.StatisticsField, value) != true)) {
this.StatisticsField = value;
this.RaisePropertyChanged("Statistics");
}
}
}

[System.Runtime.Serialization.DataMemberAttribute()]
public WebApplication1.ServiceReference2.WaitingCall[] WaitingCalls {
get {
return this.WaitingCallsField;
}
set {
if ((object.ReferenceEquals(this.WaitingCallsField, value) != true)) {
this.WaitingCallsField = value;
this.RaisePropertyChanged("WaitingCalls");
}
}
}

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

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="QueueStat", Namespace="http://schemas.datacontract.org/2004/07/Cti.WebServices")]
[System.SerializableAttribute()]
public partial class QueueStat : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {

[System.NonSerializedAttribute()]
private System.Runtime.Serialization.ExtensionDataObject extensionDataField;

[System.Runtime.Serialization.OptionalFieldAttribute()]
private int AverageWaitTimeField;

[System.Runtime.Serialization.OptionalFieldAttribute()]
private int CallCountField;

[global::System.ComponentModel.BrowsableAttribute(false)]
public System.Runtime.Serialization.ExtensionDataObject ExtensionData {
get {
return this.extensionDataField;
}
set {
this.extensionDataField = value;
}
}

[System.Runtime.Serialization.DataMemberAttribute()]
public int AverageWaitTime {
get {
return this.AverageWaitTimeField;
}
set {
if ((this.AverageWaitTimeField.Equals(value) != true)) {
this.AverageWaitTimeField = value;
this.RaisePropertyChanged("AverageWaitTime");
}
}
}

[System.Runtime.Serialization.DataMemberAttribute()]
public int CallCount {
get {
return this.CallCountField;
}
set {
if ((this.CallCountField.Equals(value) != true)) {
this.CallCountField = value;
this.RaisePropertyChanged("CallCount");
}
}
}

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

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="WaitingCall", Namespace="http://schemas.datacontract.org/2004/07/Cti.WebServices")]
[System.SerializableAttribute()]
public partial class WaitingCall : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {

[System.NonSerializedAttribute()]
private System.Runtime.Serialization.ExtensionDataObject extensionDataField;

[System.Runtime.Serialization.OptionalFieldAttribute()]
private System.DateTime CallStartField;

[System.Runtime.Serialization.OptionalFieldAttribute()]
private string CalledIDField;

[System.Runtime.Serialization.OptionalFieldAttribute()]
private string CallerIDField;

[global::System.ComponentModel.BrowsableAttribute(false)]
public System.Runtime.Serialization.ExtensionDataObject ExtensionData {
get {
return this.extensionDataField;
}
set {
this.extensionDataField = value;
}
}

[System.Runtime.Serialization.DataMemberAttribute()]
public System.DateTime CallStart {
get {
return this.CallStartField;
}
set {
if ((this.CallStartField.Equals(value) != true)) {
this.CallStartField = value;
this.RaisePropertyChanged("CallStart");
}
}
}

[System.Runtime.Serialization.DataMemberAttribute()]
public string CalledID {
get {
return this.CalledIDField;
}
set {
if ((object.ReferenceEquals(this.CalledIDField, value) != true)) {
this.CalledIDField = value;
this.RaisePropertyChanged("CalledID");
}
}
}

[System.Runtime.Serialization.DataMemberAttribute()]
public string CallerID {
get {
return this.CallerIDField;
}
set {
if ((object.ReferenceEquals(this.CallerIDField, value) != true)) {
this.CallerIDField = value;
this.RaisePropertyChanged("CallerID");
}
}
}

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

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://www.tix.nl/CtiWebService", ConfigurationName="ServiceReference2.ICtiWebService")]
public interface ICtiWebService {

[System.ServiceModel.OperationContractAttribute(Action="http://www.tix.nl/CtiWebService/ICtiWebService/GetQueueStats", ReplyAction="http://www.tix.nl/CtiWebService/ICtiWebService/GetQueueStatsResponse")]
WebApplication1.ServiceReference2.QueueInfo[] GetQueueStats();

[System.ServiceModel.OperationContractAttribute(Action="http://www.tix.nl/CtiWebService/ICtiWebService/GetQueueStats", ReplyAction="http://www.tix.nl/CtiWebService/ICtiWebService/GetQueueStatsResponse")]
System.Threading.Tasks.Task<WebApplication1.ServiceReference2.QueueInfo[]> GetQueueStatsAsync();
}

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public interface ICtiWebServiceChannel : WebApplication1.ServiceReference2.ICtiWebService, System.ServiceModel.IClientChannel {
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public partial class CtiWebServiceClient : System.ServiceModel.ClientBase<WebApplication1.ServiceReference2.ICtiWebService>, WebApplication1.ServiceReference2.ICtiWebService {

public CtiWebServiceClient() {
}

public CtiWebServiceClient(string endpointConfigurationName) :
base(endpointConfigurationName) {
}

public CtiWebServiceClient(string endpointConfigurationName, string remoteAddress) :
base(endpointConfigurationName, remoteAddress) {
}

public CtiWebServiceClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
base(endpointConfigurationName, remoteAddress) {
}

public CtiWebServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(binding, remoteAddress) {
}

public WebApplication1.ServiceReference2.QueueInfo[] GetQueueStats() {
return base.Channel.GetQueueStats();
}

public System.Threading.Tasks.Task<WebApplication1.ServiceReference2.QueueInfo[]> GetQueueStatsAsync() {
return base.Channel.GetQueueStatsAsync();
}
}
}


Viewing all articles
Browse latest Browse all 555

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>