Click here to Skip to main content
15,903,817 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All I'm a little desperate for help. I have a web service that runs fine on my local machine but when I port it over to the production web server I get the following error:

"System.Net.WebException: The remote server returned an error: (500) Internal Server Error. at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request) at System.Net.WebClient.DownloadString(Uri address) at System.Net.WebClient.DownloadString(String address) at edChartLink2.edChartLink2.GetToken(String acctNum, String MRN) in C:\Inetpub\wwwroot\edChartLink2\edChartLink2\edChartLink.asmx.cs:line 50 "


Code Snippet is:

48            string tokenURL= "http://emhaallrca/hmaled_emh/GetToken.aspx?system=3";
49            string strToken = "";            
50            strToken = client.DownloadString(tokenURL);


the page I'm calling from my web service both reside on the same web server "emhaallrca"

Any help would be greatly appreciated.

Thanks
Jose'
Posted
Updated 23-Feb-11 3:18am
v2
Comments
Ankur\m/ 23-Feb-11 9:28am    
If you have access to the production server, try checking the event logs. It may give you some more hint. You may also check Httperr log file (IIS 6+). They have come to my rescue before.

Rule of thumb:
Never ever use machine name/server name is your code unless there is no other way to do it. Reason is simple (which is also obvious is your case) that it will simply not work when you move from one environment to another.

Now, to resolve your problem. We can do two things.

1.) If this is local (within your application) webservice that simply use a relative url. Something like
string tokenURL = GetApplicationUrl() + "/hmaled_emh/GetToken.aspx?system=3";


Where GetApplicationUrl() should return your application url. Shouldn't be difficult to write a fuction for this.

2.) If webservice is hosted somewhere else i.e. outside your application than

string tokenURL = "http://YOURDOMAINNAME/hmaled_emh/GetToken.aspx?system=3";
 
Share this answer
 
Comments
Jose Garcia 23-Feb-11 9:57am    
Yes this makes a lot of sense and I was looking at that. I'll change my code. I'm new to this so please forgive my ignorance. Why would I need the application url if by using ".hmaled_emh/Get...." I'm local to that machine ?

Thanks
Jose Garcia 23-Feb-11 11:44am    
Hi maybe you can help me again. In the above, my code is under the web app edChartLink2 however in : string tokenURL= "http://emhaallrca/hmaled_emh/GetToken.aspx?system=3"; this is in web app hmaled_emh.

I can get the current app url by using HttpContext.Current etc. However this will give me the relative url of my current app. not the url for "hmaled_emh" app any ideas.

Thanks again for your help
Jose Garcia 24-Feb-11 7:48am    
Hi I tried using all kinds of code to get this to work to no avail. I have used httpcontext.current.request.applicationPath. I used server.mappath etc etc FInally I moved the web service to another machine so the url I'm calling is outside on my web server. I figure I can use option 2 above and it still doesn't work. I'm at a total lost. Can anybody out there share some light on this. I have google for hours no help either

Thanks
I did find the solution just use WebRequest as follows and it works like a charm:

private string callToGetToken()
{
WebRequest tokenRequest = WebRequest.Create("http://emhaallrca/hmaled_emh/GetToken.aspx");
tokenRequest.Method = "POST";
string urlPostData = "system=3";
byte[] tokenByteArray = Encoding.UTF8.GetBytes(urlPostData);
tokenRequest.ContentType = "application/x-www-form-urlencoded";
Stream tokenDataStream = tokenRequest.GetRequestStream();
tokenDataStream.Write(tokenByteArray, 0, tokenByteArray.Length);
tokenDataStream.Close();
WebResponse tokenResponse = tokenRequest.GetResponse();
tokenDataStream = tokenResponse.GetResponseStream();
StreamReader tokenReader = new StreamReader(tokenDataStream);
string tokenData = tokenReader.ReadToEnd();

return tokenData;

}

Hope this helps somebody else I spent a few days on this.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900