I'm still getting the same error. Would it help to see the service code
itself? I'm pasting it below in case someone can decipher. Thanks.
using System;
using System.IO;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.Services;
using System.Net;
using System.Web;
/// <summary>
/// Summary description for StockServices.
/// </summary>
[WebService (Namespace="http://enterprise.intranet.com")]
public class StockServices : System.Web.Services.WebService
{
WebProxy myProxy;
public StockServices()
{
InitializeComponent();
}
#region Component Designer generated code
//Required by the Web Services Designer
private IContainer components = null;
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing); }
#endregion
[WebMethod]
public string GetQuote(string ticker)
{
string stockURL, page, retval;
try
{
stockURL = GetURL(ticker);
page = GetPageContent(stockURL);
retval = ParsePage(page);
}
catch (ArgumentOutOfRangeException)
{
retval = "Invalid Ticker!";
}
catch (Exception)
{
retval = "Unknown Error";
}
return retval;
}
[WebMethod]
public DataSet GetQuotes(string tickers)
{
char[] splitter = {' '};
string[] _tickers = tickers.Trim().Split(splitter);
Int32 i, ticks;
ticks = _tickers.Length;
DataSet ds = new DataSet();
DataTable dt = new DataTable("StockData");
DataColumn dc;
dc = dt.Columns.Add("Ticker",System.Type.GetType("Syste m.String"));
dc = dt.Columns.Add("Price",System.Type.GetType("System .String"));
for (i = 0; i < ticks; i++)
{
DataRow dr = dt.NewRow();
dr["Ticker"] = _tickers[i].ToUpper();
dr["Price"] = GetQuote(_tickers[i]);
dt.Rows.Add(dr);
}
ds.Tables.Add(dt);
return ds;
}
public void SetProxy()
{
myProxy = new WebProxy("000.000.000.000", 80);
myProxy.Credentials = new NetworkCredential("sysid", "syspw");
}
private string GetURL(string ticker)
{
StringBuilder url = new StringBuilder();
url.Append("http://finance.yahoo.com/q/ecn?s=");
url.Append(ticker);
return url.ToString();
}
private string ParsePage(string page)
{
Int32 i;
i = page.IndexOf("Last Trade:");
page = page.Substring(i);
i = page.IndexOf("<b>");
page = page.Substring(i);
i = page.IndexOf("</b>");
page = page.Substring(0,i);
page = Regex.Replace(page,"<b>","");
return page;
}
public string GetPageContent(string url)
{
WebRequest wreq;
WebResponse wres;
StreamReader sr;
String content;
wreq = (HttpWebRequest)WebRequest.Create(url);
SetProxy();
wreq.Proxy = myProxy;
wreq.Credentials = myProxy.Credentials;
// make the HTTP call
wres = (HttpWebResponse)wreq.GetResponse();
sr = new StreamReader(wres.GetResponseStream());
content = sr.ReadToEnd();
sr.Close();
return content;
}
}
<> wrote in message
news: ups.com...
>I meant.
>> > remoteWebService.Proxy = wp
> pr was an instance of WebProxy used in our production code.
>
> Andy
>
> J Ames wrote:
>> What is the reference to "pr"?
>>
>> Actually, I *didn't* pass anything to the proxy property of the service
>> object in my client app. I set all that up in the web service itself
>> directly. So when I do an http test in the browser of the service it
>> uses
>> the credentials and returns data successfully. It's when I create a
>> client
>> app to consume that service that the proxy seems to fail. Are you saying
>> I
>> need to set the proxy property *again* in the client web app?
>>
>> J
>>
>> <> wrote in message
>> news: oups.com...
>> > My bad, I did not read your question carefully.
>> > So you've already done something like the following.
>> >
>> > 'Assume RemoteWebService is a remote web service proxy class.
>> > Dim remoteWebService As New RemoteWebService
>> >
>> > 'WebProxy to get request past company firewall
>> > Dim wp As New WebProxy("http://webproxy.example.com", 80)
>> > 'Assign a user credentials to wp
>> > wp.Credentials = New NetworkCredentials("myusername", "mypassword",
>> > "mydomain")
>> >
>> > remoteWebService.Proxy = pr
>> >
>> > 'Call a webmethod on the remote web service
>> > Dim myResults As String = remoteWebService.GetSomeResults()
>> >
>> > Andy
>> >
>> > wrote:
>> >> If you're consuming a web service on your local machine then a web
>> >> proxy does not need to be set.
>> >>
>> >> J Ames wrote:
>> >> > I'm confused on this one. I work behind our company firewall. I
>> >> > created a
>> >> > web service that accesses an external web site, using the WebProxy
>> >> > class,
>> >> > and when I test the web service in the browser, it works perfectly.
>> >> > It
>> >> > passes the correct credentials and returns data as expected.
>> >> > However,
>> >> > when
>> >> > I attempt to consume the web service in an ASP.NET project, it
>> >> > fails.
>> >> > I'm
>> >> > getting a http error (bad gateway), so I think it's failing at the
>> >> > proxy.
>> >> > I'm not sure why it would do that since it sets the proxy
>> >> > credentials
>> >> > in the
>> >> > service and works on a browser http request.
>> >> >
>> >> > Is there some other step I need to take?
>> >> >
>> >> > Thanks,
>> >> > J
>> >
>