I am consuming a WCF service and receiving the error message “The remote server returned an error: (400) Bad Request.” when consuming via WebClient
public class WebClientService : WebClient
...
base.Credentials = CredentialCache.DefaultCredentials;
base.OpenReadCompleted += new OpenReadCompletedEventHandler(ReadJsonStringAsyncComplete);
base.OpenReadAsync(new Uri("http://localhost/xxxx.svc/GetData"));
...
The WCF service to be consumed is as follows (note that both exist within the same solution (different projects)
Contract/Interface:-
[OperationContract]
[WebInvoke(Method = "GET", UriTemplate = "/GetData", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
IList<MyType> GetData();
Implementation:-
public IList<MyType> GetData()
{
return (new MyTypeRepository()).All.ToList();
}
The configuration:-
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service name="xxxx.Service.MyService" behaviorConfiguration="DataExtractBehavior">
<endpoint address="http://localhost:1422/MyService.svc" binding="webHttpBinding" bindingConfiguration="DataExtractBinding" behaviorConfiguration="MyEndpointBehavior" contract="xxxx.Service.Common.IMyService"></endpoint>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="MyEndpointBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="Default">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceAuthorization principalPermissionMode="UseAspNetRoles" />
<serviceCredentials>
<windowsAuthentication allowAnonymousLogons="false" includeWindowsGroups="true" />
</serviceCredentials>
</behavior>
<behavior name="DataExtractBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<etwTracking profileName="EndToEndMonitoring Tracking Profile" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<etwTracking profileName="EndToEndMonitoring Tracking Profile" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="DataExtractBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows"></transport>
</security>
</binding>
</webHttpBinding>
</bindings>
I can view the service definition page via http://localhost:1422/xxxx.svc however I can’t seem to call the method GetData (added onto the end of the URI – http://localhost:1422/xxxx.svc/GetData)
Does anyone know why I would get a HTTP 400 – Bad Request
Many thanks
Travis
The problem was entirely my fault – I was making a “Post” request to the above service which is contracted as a “Get” request