0

Can someone help me? I load ASMX as XMLDocument, I use following code:

string url = "http://www.*******.com/WebService.asmx/Test";
    wsResponse.Load(url);
    string XMLDocument = wsResponse.InnerXml;
    Response.ContentType = "text/xml";
    Response.Write(XMLDocument);

On production server I receved SERVER INTERNAL Error, it is on shared hosting. On local host the web service is consumed successful. The web service return a simple string as "service test" The service is request by HTTP GET

What Can caused the problem and how can I fix it.

P.S. I try to use this approach, because on shared hosting they they suddendly stop to support cross domain web service consuming, so I can not consume the service via ajax

enter image description here

Adam
  • 16,089
  • 6
  • 66
  • 109
Tiho
  • 123
  • 2
  • 8

3 Answers3

1

Any HTTP error code starting with "5" is a server error. That means that it's an unhandled exception inside of your service. The exception may possibly only occur when you access the service in this manner, but the exception is certainly in the service.

Look in the Application event log to see if details of the exception were logged. Otherwise, either debug the service, or else look wherever else the service may be logging exceptions.

FYI, when you access the service that way, you're using the HTTP GET verb. In the web.config of the service, you need to enable the HttpGet protocol. It is disabled by default, and you'll need to enable it:

<configuration>
    <system.web>
    <webServices>
        <protocols>
            <add name="HttpGet"/>
        </protocols>
    </webServices>
    </system.web>
</configuration>

Finally, I just want to make sure you know that the ASMX technology is a legacy technology, and should not be used for new development.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • 10x for answer, yes i know that asmx is an old technology but the project was build a long time ago and I wont to fix it with minimum efforts. "HttpGet" is also set in the web.config . I have a look on Hosting panel and don't find place from which to access application log, anyway I will ask the suuport. – Tiho May 04 '12 at 17:07
0

That, for sure, is a weird way of querying a web service. Normally, you add a service reference / proxy class and specify the service endpoint in the web.config.

You can read that here : http://msdn.microsoft.com/en-US/library/y92e0td0.aspx

If you can't use this method for whatever reason, I guess ( this is theoric) that you can declare an HttpRequest with your web service url and get the response as string

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Machinegon
  • 1,855
  • 1
  • 28
  • 45
0

It seems the problem is in the remote server as it is expecting a valid user agent.

Here's the fix:

var m_strFilePath = "http://www.google.com/ig/api?weather=12414&hl=it";
        string xmlStr;
        using (var wc = new WebClient())
        {
            wc.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
            TaskCompletionSource<string> tcs = new TaskCompletionSource<string>();
            xmlStr = wc.DownloadString(m_strFilePath);
        }
        xdoc.LoadXml(xmlStr);

Here's the article on Stackoverflow website: webclient The remote server returned an error: (500) Internal Server Error

Community
  • 1
  • 1