473,406 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Generating a web request from a Winform Application using WebServi

How to generate a web request from a Winform Application using a WebService?

In a C# Windows Application, when I try to genrate a web request using the
following code, it is woking fine

Winform code
---------------

Browser.DocumentHTML = "";
string HTMLData="";
string Error = "";
try
{
Uri myUri = new Uri(TxtURL.Text);
CredentialCache credCache = new CredentialCache();
HttpWebRequest MyRequest = (HttpWebRequest)WebRequest.Create(myUri);
MyRequest.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse MyResponse = (HttpWebResponse)MyRequest.GetResponse();
StreamReader Reader = new StreamReader(MyResponse.GetResponseStream());

HTMLData = Reader.ReadToEnd();
Reader.Close();
MyResponse.Close();

}
catch(Exception ex)
{
HTMLData = "";
Error = ex.ToString();
}
if (HTMLData != "")
Browser.DocumentHTML = HTMLData;
else
MessageBox.Show(Error);

Here Browser is a AxDHTMLEdit control

But when I tried the following code in a web service it is not working.

Web Service Code
--------------------
[WebMethod]
public string GetURL(string URL, out string Error)
{
string HTMLData="";
Error = "";
try
{
Uri myUri = new Uri(URL);
CredentialCache credCache = new CredentialCache();
HttpWebRequest MyRequest =
(HttpWebRequest)WebRequest.Create(myUri);
MyRequest.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse MyResponse =
(HttpWebResponse)MyRequest.GetResponse();
StreamReader Reader = new
StreamReader(MyResponse.GetResponseStream());

HTMLData = Reader.ReadToEnd();
Reader.Close();
MyResponse.Close();

}
catch(Exception ex)
{
HTMLData = "";
Error = ex.ToString();
}
return HTMLData;
}

Code to Access the Web Service in a Windows Application
------------------------------------------------------------------
TestService MyWebService = new TestService();
string Error = "";
try
{
string HTMLData = MyWebService.GetURL(TxtURL.Text, out Error);
if (HTMLData != "")
Browser.DocumentHTML = HTMLData;
else
{
MessageBox.Show(Error);
}

}
catch(Exception ex)
{
TxtBrowser.Text = ex.ToString();
}

But it generates the exception

System.Net.WebException: The remote server returned an error: (500) Internal
Server Error.
at System.Net.HttpWebRequest.CheckFinalStatus()
at System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult asyncResult)
at System.Net.HttpWebRequest.GetResponse()
at CenService.TunnelService.TunnelURL(String URL, String& Error)

Can anybody please tell me the reason for this error and how to resolve this
issue.

Windows Application Method(Direct)
Windows Application -> Web Site
In this case, it creates the instance of a WebRequest and send to the
WebServer. And get the Response from WebServer and Displays it in a DHTML
edit control.

Web Service Method (Indirect)
Windows Application -> Web Service -> Web Site

In this case, it creates the instance of a WebService from a Windows
Application and through webmethod of that webservice, it sends the url to
WebService.
From WebService, it generates another webrequest to get the web site
(similar to previous method) and get the response inside the webservice and
send the response string to client windows application.

I want to know why it is not allowing to generate a web request from a web
service?
Thanks in advance
Cenray

Jul 21 '05 #1
0 2891

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: localhost | last post by:
I am looking for any info on creating an MDI WinForms application that uses the "main executable" as a main window container (along with a menu), but can launch other .exe from a menu that act as...
1
by: Pramod Thewarkar | last post by:
Hi, I have deployed my winform application on iis server in a virtual directory. On the start of my application, it is reading some information from the config file (app.config). When i am...
3
by: mphanke | last post by:
Hi, I would like to implement a windows service which forks a configurable number of threads which all siten to the same port and reply to requests of different clients. How would I implement...
5
by: TomR | last post by:
We are having problems with synchronus web request calls blocking our ASP.NET performance. Here is the setup: We have a php script running on Apache at Site A on the internet. This script does...
9
by: hari krishna | last post by:
hi, I want to send the data from dataset information to Excel through ASP.Net. there will be no XL installed on web server. web server is win 2000 server machine. I am using visual basic code in...
4
by: Lee Chapman | last post by:
Hi, I am having difficulty getting the ASP.NET framework to generate valid XHTML. My immediate problem surrounds user input in, for example, textbox controls. I consider characters such as...
0
by: Cenray | last post by:
How to generate a web request from a Winform Application using a WebService? In a C# Windows Application, when I try to genrate a web request using the following code, it is woking fine ...
0
by: otto | last post by:
Hi, all: We have a Windows application that make operations against an Oracle database. The business logic components are in the server and are accesible from the client interface trought a...
6
by: WT | last post by:
Hello, Using VS2005. I have an assembly library that can be called from a Web site asp.net application or from a winform application. From this library I need to retrieve a path using simply a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.