title: C# How to get/set data from asmx Web Service
body: <p>I'm using VisualStudio2013. Its important to note for readers that the code which this asmx is derived from works perfectly but I do not know how to use the asmx WebService. I downloaded the whole nine yards from here <a href="https://sourceforge.net/projects/shorturl-dotnet/" rel="nofollow">https://sourceforge.net/projects/shorturl-dotnet/</a></p>
  
  <p>I cannot figure out how to get/set properties of the following CreateUrl() WebMethod. I want to learn how to use the entire WebService but started here. </p>
  
  <p>In the example that follows I send a URL to the CreateURL() method which will shorten the URL and perform other tasks; I do not know how to get properties from the returned ShortUrl.Container Class: I have not been successful accessing the data after the class(es) are returned to my calling method.</p>
  
  <p>// WebMethod</p>
  
  <pre><code>public class API  : System.Web.Services.WebService {
  
  [WebMethod]
  public ShortUrl.Container CreateUrl(string real_url)
  {
      ShortUrl.Container oShortUrl = new ShortUrl.Container();
  
      oShortUrl.RealUrl = real_url;
      oShortUrl.ShortenedUrl = ShortUrl.Utils.UniqueShortUrl();
      oShortUrl.CreateDate = DateTime.Now;
      oShortUrl.CreatedBy = HttpContext.Current.Request.UserHostAddress;
  
      ShortUrl.Utils.AddUrlToDatabase(oShortUrl);
  
      oShortUrl.ShortenedUrl = ShortUrl.Utils.PublicShortUrl(oShortUrl.ShortenedUrl);
  
      return oShortUrl;
      }
  }
  </code></pre>
  
  <p>// ShortUrl.Container class returned as oShortUrl</p>
  
  <pre><code>namespace ShortUrl
  {
      /// &lt;summary&gt;
      /// Container for the ShortURL object
      /// &lt;/summary&gt;
      public class Container
      {
          private string _real_url;
          private string _short_url;
          private DateTime _create_date;
          private string _created_by;
  
          public Container()
          {
              this.CreateDate = DateTime.Now;
              this.CreatedBy = "tap";
              this.RealUrl = null;
              this.ShortenedUrl = "Unknown";
          }
  
          public string RealUrl
          {
              get { return _real_url;  }
              set { _real_url = value; }
          }
  
          public string ShortenedUrl
          {
              get { return _short_url;  }
              set { _short_url = value; }
          }
  
          public DateTime CreateDate
          {
              get { return _create_date;  }
              set { _create_date = value; }
          }
  
          public string CreatedBy
          {
              get { return _created_by;  }
              set { _created_by = value; }
          }
      }
  }
  </code></pre>
  
  <p>In VS2013 I add the Service Reference to point to <a href="http://tap.tools.api.asmx" rel="nofollow">http://tap.tools.api.asmx</a> as the service endpoint and name the VS2013 reference as ShortenUrl. VS2013 generates the APISoapClient and Container classes.</p>
  
  <pre><code>// get/set properties of the ShortUrl.Container class
  // by means of APISoapClient
  ShortenUrl.APISoapClient u = new ShortenUrl.APISoapClient();
  u.CreateUrl("http://clintongallagher.com/tag-target-url.html");
  
  
  // get/set properties of the ShortUrl.Container class
  // by means of Container class
  ShortenUrl.Container c = new ShortenUrl.Container();
  string url = c.RealUrl;
  </code></pre>
  
  <p>I'm  not getting anywhere with either and I think my problem is the instance of the oShortUrl object instantiated within the public ShortUrl.Container CreateUrl(string real_url) method. I do not know how to get any of the properties from that instance of oShortUrl the Container class returns to my methods.</p>
  
  <pre><code>// oShortUrl 
  ShortUrl.Container oShortUrl = new ShortUrl.Container();
  </code></pre>
  
  <p>Odd as it may sound as old and outdated the use of asmx happens to be I never worked with -any- WebServices yet which explains why I am weak and throw myself to the mercy of the court.</p>
  
  <p>// EDIT: 2016-07-19 ~2:41pm</p>
  
  <p>VS2013 generated several classes from the WSDL two of which appear to be useful as seen in Intellisense...</p>
  
  <p>// class APISoapClient and class Container</p>
  
  <p>When I use a local variable with APISoapClient a shortened URL is generated as I can see using SQL Management Studio and note all of the data is properly generated but I am not able to get/set on any other WebMethods or properties with to get/set data...</p>
  
  <pre><code>// Exposes two WebMethods: CreateUrl and GetUrl    
  ShortenUrl.APISoapClient u = new ShortenUrl.APISoapClient();  
  
  // Does generate the shortened URL
  u.CreateUrl("http://clintongallagher.com/tag-target-url.html");
  // Should return the URL that was shortened but doesn't
  u.GetUrl("i2Z5H");
  </code></pre>
  
  <p>And...</p>
  
  <pre><code>// Exposes the properties in Intellisense but does not return data
  ShortenUrl.Container c = new ShortenUrl.Container();
  
  // returns 1/1/0001 12:00:00 AM 
  lblCreateDate.Text = "CreateDate: " + c.CreateDate.ToString();
  // returns nothing
  lblCreatedBy.Text = "CreatedBy: " + c.CreatedBy;
  // returns nothing
  lblRealUrl.Text = "RealUrl: " + c.RealUrl;
  // returns ShortenUrl.Container
  lblShortenedUrl.Text = "ShortenedUrl: " + u.GetUrl("i2Z5H"); 
  </code></pre>