473,772 Members | 2,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Documen tHTML = "";
string HTMLData="";
string Error = "";
try
{
Uri myUri = new Uri(TxtURL.Text );
CredentialCache credCache = new CredentialCache ();
HttpWebRequest MyRequest = (HttpWebRequest )WebRequest.Cre ate(myUri);
MyRequest.Crede ntials = CredentialCache .DefaultCredent ials;
HttpWebResponse MyResponse = (HttpWebRespons e)MyRequest.Get Response();
StreamReader Reader = new StreamReader(My Response.GetRes ponseStream());

HTMLData = Reader.ReadToEn d();
Reader.Close();
MyResponse.Clos e();

}
catch(Exception ex)
{
HTMLData = "";
Error = ex.ToString();
}
if (HTMLData != "")
Browser.Documen tHTML = 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.Cre ate(myUri);
MyRequest.Crede ntials = CredentialCache .DefaultCredent ials;
HttpWebResponse MyResponse =
(HttpWebRespons e)MyRequest.Get Response();
StreamReader Reader = new
StreamReader(My Response.GetRes ponseStream());

HTMLData = Reader.ReadToEn d();
Reader.Close();
MyResponse.Clos e();

}
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.Ge tURL(TxtURL.Tex t, out Error);
if (HTMLData != "")
Browser.Documen tHTML = HTMLData;
else
{
MessageBox.Show (Error);
}

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

But it generates the exception

System.Net.WebE xception: The remote server returned an error: (500) Internal
Server Error.
at System.Net.Http WebRequest.Chec kFinalStatus()
at System.Net.Http WebRequest.EndG etResponse(IAsy ncResult asyncResult)
at System.Net.Http WebRequest.GetR esponse()
at CenService.Tunn elService.Tunne lURL(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 2936

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

Similar topics

2
324
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 SDI forms themselves. Thanks.
1
1792
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 running this application by typing the URL of the virtual directory (and name of my application), the assemblies are getting downloaded to my machine's GAC but the application is giving error that cannot find the configuration file. Is there any way...
3
3314
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 something like this? Martin
5
383
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 nothing more than wait 15 seconds before serving a page. (You can try it if you want. www.337skymaster.com/mypost.php) Using this page, we can open four IE browsers on the same machine and start each browser at the same time, and have all four...
9
4437
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 asp.net. The Xl sheet should not be opened in the browser. All the information from dataset(datatable,datarows) should be sent to XL and the file name should be given dynamically through program and the xl file should be saved dynamically through...
4
1605
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 less-than and ampersand perfectly valid in user input. So I've disabled request validation by adding the following to my web.config file.
0
303
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 Winform code --------------- Browser.DocumentHTML = ""; string HTMLData="";
0
1097
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 WebService. The business logic components call the data access layer components and obtain the results. tha problem is as follows: one application requirement is that when a user make some operations, the tables (or rows) he is working to remain locked...
6
2811
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 key like 'libPath'. As far as winform and asp.net share the same common base class for settings, SettingsBase, how to manage this ? For winform the value should be set in app.config and for web site in
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10103
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9911
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8934
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7460
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6713
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.