Skip to content

Novice Requires Help - Web Reference - Classes

Andrew

Asked Mar 9, 2006, 6:41 AM EST8 answers
Share
LinkedInX
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

8 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Could you please post your class and the line of code you are using to reference it.
    0
  • 0

    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

    0
  • 0
    That cannot be you entire c# code surely? i cannot help you if you only post one method from your entire class, by this i mean c# class. You are referencing other classes within this code but there is no sign of them ( testwebserv1 or cpLatestBrief for example )
    0
  • 0
    That's all I have, really.

    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
    0
  • 0
    Hi there, No they are not one and the same, you are refercing classes that you do not have, for example - testwebserv1.WebReference.callbackelement cbe = new callbackelement(); is referencing a class called testwebserv1 and since you do not have this class you cannot reference it.. All i can see from that link you posted is php, did you post the right link? as it isnt a c# class
    0
  • 0
    I've got part of the reference working: -

    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

    0
  • 0
    Hi again. Right ok, so the methods you are referencing are via the web, you did not state this before and that link you posted only showed me the script of a php page and had nothing contained within it that looked remotely like c# code.. as for your new question, please can you post the exact errors you are getting as otherwise people are going to be guessing what the problem is..
    0
  • 0

    Hi,

    Here is the code from the Class, once referenced from the web: -

    //------------------------------------------------------------------------------
    // <autogenerated>
    //     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.
    // </autogenerated>
    //------------------------------------------------------------------------------

    //
    // 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;
       
       
        /// <remarks/>
        [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;
           
            /// <remarks/>
            public SendSmsService() {
                this.Url = "http://gw1.aql.com/soap/sendsmsservice.php";
            }
           
            /// <remarks/>
            [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]));
            }
           
            /// <remarks/>
            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);
            }
           
            /// <remarks/>
            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]));
            }
           
            /// <remarks/>
            [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]));
            }
           
            /// <remarks/>
            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);
            }
           
            /// <remarks/>
            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]));
            }
           
            /// <remarks/>
            [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]));
            }
           
            /// <remarks/>
            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);
            }
           
            /// <remarks/>
            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]));
            }
           
            /// <remarks/>
            [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]));
            }
           
            /// <remarks/>
            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);
            }
           
            /// <remarks/>
            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]));
            }
        }
       
        /// <remarks/>
        [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 {
           
            /// <remarks/>
            public string username;
           
            /// <remarks/>
            public string password;
        }
       
        /// <remarks/>
        [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://soap.sendsms.aql.com")]
        public class callbackelement {
           
            /// <remarks/>
            public string callbackurl;
           
            /// <remarks/>
            public callbacktypeoptions callbacktype;
        }
       
        /// <remarks/>
        [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://soap.sendsms.aql.com")]
        public enum callbacktypeoptions {
           
            /// <remarks/>
            NONE,
           
            /// <remarks/>
            HTTPGET,
        }
       
        /// <remarks/>
        [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://soap.sendsms.aql.com")]
        public enum mtype {
           
            /// <remarks/>
            text,
           
            /// <remarks/>
            flash,
        }
       
        /// <remarks/>
        [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://soap.sendsms.aql.com")]
        public enum encodingvalues {
           
            /// <remarks/>
            [System.Xml.Serialization.XmlEnumAttribute("7")]
            Item7,
           
            /// <remarks/>
            [System.Xml.Serialization.XmlEnumAttribute("8")]
            Item8,
           
            /// <remarks/>
            [System.Xml.Serialization.XmlEnumAttribute("16")]
            Item16,
        }
       
        /// <remarks/>
        [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://soap.sendsms.aql.com")]
        public enum mmsclass {
           
            /// <remarks/>
            [System.Xml.Serialization.XmlEnumAttribute("80")]
            Item80,
           
            /// <remarks/>
            [System.Xml.Serialization.XmlEnumAttribute("81")]
            Item81,
           
            /// <remarks/>
            [System.Xml.Serialization.XmlEnumAttribute("82")]
            Item82,
           
            /// <remarks/>
            [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

    0