title: Using Web Service or Web Service Reference
body: <p>This relates specifically to .NET.  And I've decided to use the Web service Reference instead of Web Service...I think though my questions below really are for either situation and I want to try to get the overall idea of this.</p>
  
  <p><strong>So here is the issue for me.</strong>  Let me first explain where I'm coming from.  One past projects,  I've talked to a couple APIs before by creating manual classes such as a GetPicturesRequest.cs and a GetPicturesResponse.cs for example that would hold state for me.  I'd have a base class called Request.cs that did the actual sending of the api call:</p>
  
  <pre><code>Stream requestStream;
  Stream responseStream;
  XmlDocument doc = new XmlDocument();
  doc = CreateRequestXML();
  
  // Determins if API call needs to use a session based URI
  string requestURI = UseAuthURI == true ? _requestURIAuthBased + JSessionID : _requestURI;
  
  byte[] data = XmlUtil.DocumentToBytes(doc);
  
  // Create the atual Request instance
  HttpWebRequest request = CreateWebRequest(requestURI, data.Length);
  request.ContentLength = data.Length;
  request.KeepAlive = false;
  request.Timeout = 30000;
  
  // Send the Request
  requestStream = request.GetRequestStream();
  requestStream.Write(data, 0, data.Length);
  requestStream.Close();
  </code></pre>
  
  <p>Now I want to use a Web service Reference.  So I pointed and created a new reference to <a href="https://www.sandbox.paypal.com/wsdl/PayPalSvc.wsdl" rel="nofollow noreferrer">https://www.sandbox.paypal.com/wsdl/PayPalSvc.wsdl</a> in VS 2008.  I now have a Web Reference.</p>
  
  <p>I have now these questions as being a first time user of web services as opposed to doing things manually as I was to use a 3rd party API:</p>
  
  <p><strong>1)</strong> How can I specify header params?  For instance some APIs require you to send a hash (signature), sessionID, username, password, you name it along with the API method call request. How do you specify this using a web service proxy class?</p>
  
  <p><strong>2)</strong> How is the request/response objects handled or do I not need to worry about this now that I'm using a web service/reference?  I mean do I need to create a request object still and how would I receive the response?</p>
  
  <p><strong>3)</strong> When I receive the response, does the proxy class contain its state or do I have to still create a class to hold the state of the returned data from the API method call response when using web services/references?</p>
  
  <p><strong>4)</strong> When ever would I want to instead just create custom code like I did before and not use web services/reference option with WSDL?...essentially creating my own proxy classes, request objects, response objects, everything? Rather than have VS spit out a Web Reference based on a WSDL?  Is it because if it's not a SOAP based 3rd party API?  Is it because the 3rd party API does not provide a WSDL then you're forced to hand code the wrappers yourself?</p>