Hi,
I'm new to C# and need to make a Web Reference, this I've done and I can see the Class.
How do I make a reference to it in my code, do I use 'using .....'?
In the example of code for using it I have the following line: -
cpLatestBrief.authValue
there is now reference to 'cpLatestBrief', what should I do to correct this?
Hope this makes sense?
Regards
Loading
AndrewPosted Mar 9, 2006, 6:25 PM
Hi,
Here is the code from the Class, once referenced from the web: -
//------------------------------------------------------------------------------
//
// This code was generated by a tool.
// Runtime Version: 1.1.4322.2032
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
//------------------------------------------------------------------------------
//
// This source code was auto-generated by Microsoft.VSDesigner, Version 1.1.4322.2032.
//
namespace SMS.com.aql.gw1 {
using System.Diagnostics;
using System.Xml.Serialization;
using System;
using System.Web.Services.Protocols;
using System.ComponentModel;
using System.Web.Services;
///
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="SendSmsSoapHttpBinding", Namespace="http://soap.sendsms.aql.com")]
public class SendSmsService : System.Web.Services.Protocols.SoapHttpClientProtocol {
public auth authValue;
///
public SendSmsService() {
this.Url = "http://gw1.aql.com/soap/sendsmsservice.php";
}
///
[System.Web.Services.Protocols.SoapHeaderAttribute("authValue")]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://soap.sendsms.aql.com#sendsms", RequestNamespace="http://soap.sendsms.aql.com", ResponseNamespace="http://soap.sendsms.aql.com", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
[return: System.Xml.Serialization.XmlElementAttribute("responsecode")]
public string SoapSendSms([System.Xml.Serialization.XmlArrayItemAttribute("number", IsNullable=false)] string[] destinationarray, string originator, string message, mtype messagetype, [System.Xml.Serialization.XmlElementAttribute(DataType="integer")] string maxconcat, System.DateTime sendtime, [System.Xml.Serialization.XmlIgnoreAttribute()] bool sendtimeSpecified, callbackelement dlrep, out string creditsused, out string description) {
object[] results = this.Invoke("SoapSendSms", new object[] {
destinationarray,
originator,
message,
messagetype,
maxconcat,
sendtime,
sendtimeSpecified,
dlrep});
creditsused = ((string)(results[1]));
description = ((string)(results[2]));
return ((string)(results[0]));
}
///
public System.IAsyncResult BeginSoapSendSms(string[] destinationarray, string originator, string message, mtype messagetype, string maxconcat, System.DateTime sendtime, bool sendtimeSpecified, callbackelement dlrep, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("SoapSendSms", new object[] {
destinationarray,
originator,
message,
messagetype,
maxconcat,
sendtime,
sendtimeSpecified,
dlrep}, callback, asyncState);
}
///
public string EndSoapSendSms(System.IAsyncResult asyncResult, out string creditsused, out string description) {
object[] results = this.EndInvoke(asyncResult);
creditsused = ((string)(results[1]));
description = ((string)(results[2]));
return ((string)(results[0]));
}
///
[System.Web.Services.Protocols.SoapHeaderAttribute("authValue")]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://soap.sendsms.aql.com#sendbinarysms", RequestNamespace="http://soap.sendsms.aql.com", ResponseNamespace="http://soap.sendsms.aql.com", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
[return: System.Xml.Serialization.XmlElementAttribute("responsecode")]
public string SoapSendBinarySms([System.Xml.Serialization.XmlArrayItemAttribute("number", IsNullable=false)] string[] destinationarray, string originator, [System.Xml.Serialization.XmlElementAttribute(DataType="hexBinary")] System.Byte[] data, [System.Xml.Serialization.XmlElementAttribute(DataType="hexBinary")] System.Byte[] udh, System.DateTime sendtime, [System.Xml.Serialization.XmlIgnoreAttribute()] bool sendtimeSpecified, callbackelement dlrep, encodingvalues encoding, [System.Xml.Serialization.XmlIgnoreAttribute()] bool encodingSpecified, out string creditsused, out string description) {
object[] results = this.Invoke("SoapSendBinarySms", new object[] {
destinationarray,
originator,
data,
udh,
sendtime,
sendtimeSpecified,
dlrep,
encoding,
encodingSpecified});
creditsused = ((string)(results[1]));
description = ((string)(results[2]));
return ((string)(results[0]));
}
///
public System.IAsyncResult BeginSoapSendBinarySms(string[] destinationarray, string originator, System.Byte[] data, System.Byte[] udh, System.DateTime sendtime, bool sendtimeSpecified, callbackelement dlrep, encodingvalues encoding, bool encodingSpecified, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("SoapSendBinarySms", new object[] {
destinationarray,
originator,
data,
udh,
sendtime,
sendtimeSpecified,
dlrep,
encoding,
encodingSpecified}, callback, asyncState);
}
///
public string EndSoapSendBinarySms(System.IAsyncResult asyncResult, out string creditsused, out string description) {
object[] results = this.EndInvoke(asyncResult);
creditsused = ((string)(results[1]));
description = ((string)(results[2]));
return ((string)(results[0]));
}
///
[System.Web.Services.Protocols.SoapHeaderAttribute("authValue")]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://soap.sendsms.aql.com#sendwappush", RequestNamespace="http://soap.sendsms.aql.com", ResponseNamespace="http://soap.sendsms.aql.com", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
[return: System.Xml.Serialization.XmlElementAttribute("responsecode")]
public string SoapSendWapPush([System.Xml.Serialization.XmlArrayItemAttribute("number", IsNullable=false)] string[] destinationarray, string originator, string waptitle, string wapurl, System.DateTime sendtime, [System.Xml.Serialization.XmlIgnoreAttribute()] bool sendtimeSpecified, callbackelement dlrep, out string creditsused, out string description) {
object[] results = this.Invoke("SoapSendWapPush", new object[] {
destinationarray,
originator,
waptitle,
wapurl,
sendtime,
sendtimeSpecified,
dlrep});
creditsused = ((string)(results[1]));
description = ((string)(results[2]));
return ((string)(results[0]));
}
///
public System.IAsyncResult BeginSoapSendWapPush(string[] destinationarray, string originator, string waptitle, string wapurl, System.DateTime sendtime, bool sendtimeSpecified, callbackelement dlrep, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("SoapSendWapPush", new object[] {
destinationarray,
originator,
waptitle,
wapurl,
sendtime,
sendtimeSpecified,
dlrep}, callback, asyncState);
}
///
public string EndSoapSendWapPush(System.IAsyncResult asyncResult, out string creditsused, out string description) {
object[] results = this.EndInvoke(asyncResult);
creditsused = ((string)(results[1]));
description = ((string)(results[2]));
return ((string)(results[0]));
}
///
[System.Web.Services.Protocols.SoapHeaderAttribute("authValue")]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://soap.sendsms.aql.com#sendmmsnot", RequestNamespace="http://soap.sendsms.aql.com", ResponseNamespace="http://soap.sendsms.aql.com", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
[return: System.Xml.Serialization.XmlElementAttribute("responsecode")]
public string SoapSendMMSNot([System.Xml.Serialization.XmlArrayItemAttribute("number", IsNullable=false)] string[] destinationarray, string originator, string subject, string mmsurl, [System.Xml.Serialization.XmlElementAttribute(DataType="integer")] string filesize, mmsclass @class, [System.Xml.Serialization.XmlElementAttribute(DataType="integer")] string expiry, System.DateTime sendtime, [System.Xml.Serialization.XmlIgnoreAttribute()] bool sendtimeSpecified, callbackelement dlrep, out string creditsused, out string description) {
object[] results = this.Invoke("SoapSendMMSNot", new object[] {
destinationarray,
originator,
subject,
mmsurl,
filesize,
@class,
expiry,
sendtime,
sendtimeSpecified,
dlrep});
creditsused = ((string)(results[1]));
description = ((string)(results[2]));
return ((string)(results[0]));
}
///
public System.IAsyncResult BeginSoapSendMMSNot(string[] destinationarray, string originator, string subject, string mmsurl, string filesize, mmsclass @class, string expiry, System.DateTime sendtime, bool sendtimeSpecified, callbackelement dlrep, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("SoapSendMMSNot", new object[] {
destinationarray,
originator,
subject,
mmsurl,
filesize,
@class,
expiry,
sendtime,
sendtimeSpecified,
dlrep}, callback, asyncState);
}
///
public string EndSoapSendMMSNot(System.IAsyncResult asyncResult, out string creditsused, out string description) {
object[] results = this.EndInvoke(asyncResult);
creditsused = ((string)(results[1]));
description = ((string)(results[2]));
return ((string)(results[0]));
}
}
///
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://soap.sendsms.aql.com")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="http://soap.sendsms.aql.com", IsNullable=false)]
public class auth : System.Web.Services.Protocols.SoapHeader {
///
public string username;
///
public string password;
}
///
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://soap.sendsms.aql.com")]
public class callbackelement {
///
public string callbackurl;
///
public callbacktypeoptions callbacktype;
}
///
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://soap.sendsms.aql.com")]
public enum callbacktypeoptions {
///
NONE,
///
HTTPGET,
}
///
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://soap.sendsms.aql.com")]
public enum mtype {
///
text,
///
flash,
}
///
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://soap.sendsms.aql.com")]
public enum encodingvalues {
///
[System.Xml.Serialization.XmlEnumAttribute("7")]
Item7,
///
[System.Xml.Serialization.XmlEnumAttribute("8")]
Item8,
///
[System.Xml.Serialization.XmlEnumAttribute("16")]
Item16,
}
///
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://soap.sendsms.aql.com")]
public enum mmsclass {
///
[System.Xml.Serialization.XmlEnumAttribute("80")]
Item80,
///
[System.Xml.Serialization.XmlEnumAttribute("81")]
Item81,
///
[System.Xml.Serialization.XmlEnumAttribute("82")]
Item82,
///
[System.Xml.Serialization.XmlEnumAttribute("83")]
Item83,
}
}
Here is the error: -
C:\Documents and Settings\My Documents\Visual Studio Projects\Visual C#\SMS\SMS\Form1.cs(94): An object reference is required for the nonstatic field, method, or property 'SMS.com.aql.gw1.SendSmsService.authValue'
Regards
Jason SmithPosted Mar 9, 2006, 1:20 PM
AndrewPosted Mar 9, 2006, 1:10 PM
Changed...
testwebserv1.WebReference.callbackelement cbe =
new callbackelement();To...
SMS.com.aql.gw1.callbackelement cbe =
new callbackelement();But having problems with...
cpLatestBrief.authValue =
new auth();Trying...
SMS.com.aql.gw1.SendSmsService.authValue = new auth();
But get an error?
Regards
Jason SmithPosted Mar 9, 2006, 12:55 PM
AndrewPosted Mar 9, 2006, 12:49 PM
The others you're refering to, aren't they one and the same?
The HTTPGET from the 'testwebserver1 - callbackelement' is in the class I've posted, and so is .username from the 'cpLatestBrief'.
Regards
Jason SmithPosted Mar 9, 2006, 12:38 PM
AndrewPosted Mar 9, 2006, 12:22 PM
Hi,
Thanks for the reply.
This is the class http://gw1.aql.com/soap/sendservice.php?WSDL
This is the sample code I was given: -
[CODE]
public void sendansms()
{
string [] destarr = new string[1];
destarr[0] = "44711111111";
destarr[1] = "44722222222";
cpLatestBrief.authValue = new auth();
cpLatestBrief.authValue.username = "myusername";
cpLatestBrief.authValue.password = "mypassword";
string creditsused;// = new string("");
string outdesr;// = new string("");
System.DateTime dt = DateTime.Now;
testwebserv1.WebReference.callbackelement cbe = new callbackelement();
cbe.callbackurl = "http://url.com";
cbe.callbacktype = testwebserv1.WebReference.callbacktypeoptions.HTTPGET;
if (cpLatestBrief != null)
{
try
{
//MessageBox.Show("You must enter a name.", "Name Entry Error",MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
cpLatestBrief.SoapSendSms(destarr,"orig",messagetext.Text,testwebserv1.WebReference.mtype.text,"2",dt,false,cbe,out creditsused,out outdesr);
MessageBox.Show(creditsused, "Credits used",MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
catch(SoapHeaderException e)
{
MessageBox.Show(e.Message, "Authentication error",MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
catch(SoapException e)
{
System.Xml.XmlNode node = e.Detail;
string errorcode = e.Detail.FirstChild.InnerText;
string errortext = e.Detail.FirstChild.NextSibling.InnerText;
if(errorcode == "DESTERROR-INVALIDNUMBERS")
MessageBox.Show(e.Message, "Name Entry Error",MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
else if(errorcode == "MESSAGE-NOTSUPPLIED")
MessageBox.Show(e.Message, "Name Entry Error",MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
else
MessageBox.Show(errorcode+e.Message+" "+errortext, "Name Entry Error",MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
return;
}
else
return;
}
[/CODE]
Regards,
Andrew
Jason SmithPosted Mar 9, 2006, 12:14 PM