2
votes

I tried to add a service reference to my windows form application in visual studio for accessing :

http://intranet.contoso.com/sites/Lab05/_vti_bin/ListData.svc

but after I click "go" button it returns an error with the following Details :

There was an error downloading >'http://intranet.contoso.com/sites/Lab05/_vti_bin/ListData.svc'. The request failed with HTTP status 400: Bad Request. Metadata contains a reference that cannot be resolved: >'http://intranet.contoso.com/sites/Lab05/_vti_bin/ListData.svc'. The remote server returned an unexpected response: (400) Bad Request. The remote server returned an error: (400) Bad Request. If the service is defined in the current solution, try building the solution >and adding the service reference again.

but when I enter the address in IE at first time it does not show anything but when I authenticate my self by visiting

http://intranet.contoso.com/sites/Lab05

IE will shows some xml information after entering

http://intranet.contoso.com/sites/Lab05/_vti_bin/ListData.svc

address.

I do these works in windows server 2008 R2 and visual studio 2012 on the same machine which Windows is installed.

2

2 Answers

0
votes

The issue is from authentication mode of the web application which i tried to obtain web service from. anonymous for the web application should be disable. please refer to this post for changing web application authentication on IIS Manager :

https://sharepoint.stackexchange.com/questions/22349/listdata-svc-returns-error-400-bad-request-in-visual-studio

0
votes

I faced the same problem exactly, In my case (which may be helpful for other) the problem was that I am using the "DataMemeber" attribute for the enum values like this

[DataContract]
public enum Enum1 { 
     [DataMember]
     Enum_Value_Name_1
}

this was the cause of the error mentioned above. and the correctness step was

[DataContract]
public enum Enum1 { 
     [EnumMember]
     Enum_Value_Name_1
}

I discovered this by requesting the Url of the Services in the browser. all the details of the error was written over there and they was very clean.

So if you have a similar problem, my advise is : request the WCF Service Url from the Browser and you will get more information about how to solve your (specific) problem.