views:

247

answers:

4

I am trying to call a web service from asp.net 3.5 application. I have a URL that has the DNS in it and when it is used I get the following Error.

(the xxxxxx is there for privacy concerns) The request failed with the error message: -- 301 Moved Permanently

Moved Permanently

The document has moved here.

When I use the URL with the physical IP it works just fine. Are there any setting that I am missing. I currently have the URL behavior set to dynamic so that it uses the url from the webconfig.

+1  A: 

Hm - maybe I do not understand your question correctly, but it sounds like the web service URL simply has changed from the one you use to the one returned by the 301 response (the xxxxxxxx one).

Are you sure you call the web service with exactly the xxxxxxx URL?

PS:

I have a URL that has the DNS in it

This is probably not what you wanted to say - DNS stands for Domain Name System, which would be the system that translates URLs to IP Addresses. I assume you wanted to say FQDN, meaning Fully Qualified Domain Name.

Henrik Opel
Yes, thank you for that correction
TampaRich
+1  A: 

It's possible for request rewriting to be happening on the server side, based on the incoming request, including what you pass for the hostname in the URL. A request rewrite may result in a 301 response.

In other words, requests with a hostname of www.domain.com may be rewritten, while requests using a particular ip address, even if the IP address is the address that www.domain.com resolves to, may not be rewritten.

The solution is to either use the IP address, or use the new location that you get from the 301 response.

Cheeso
A: 

If you are using a Web Reference, then you can set the AllowAutoRedirect property of the proxy instance to true. In this case, the redirection will happen behind the scenes.

John Saunders
John, that worked but the behavior is very strange. Here is what is happening, the URL that I originally had goes to the webserver, does a redirect to the FQDN URL. When I added the AllowAutoRedirect to work it works but fails since the response is the HTML sent back from the service. But if I use the FQDN directly, it works and does not fail. Not sure if that makes sense.
TampaRich
below is the error, it is sending back html instead of xml in the header. but works if I use the link that the redirect uses. Client found response content type of 'text/html;charset=ISO-8859-1', but expected 'text/xml'.The request failed with the error message:
TampaRich
A: 

Hi John,

Is there an equivalent to AllowAutoRedirect when you are using a Service Reference instead of a Web Reference?

Thanks

Marwan