我正在使用WCF服务并收到错误消息“远程服务器返回错误:(400)错误请求”。通过Web客户端消耗时正在通过webclient调用WCF方法 - HTTP 400 - 错误请求
public class WebClientService : WebClient
...
base.Credentials = CredentialCache.DefaultCredentials;
base.OpenReadCompleted += new OpenReadCompletedEventHandler(ReadJsonStringAsyncComplete);
base.OpenReadAsync(new Uri("http://localhost/xxxx.svc/GetData"));
...
要消耗的WCF服务是如下(注意的是,相同的解决方案中存在(不同的项目)
合同/接口: -
[OperationContract]
[WebInvoke(Method = "GET", UriTemplate = "/GetData", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
IList<MyType> GetData();
实施: -
public IList<MyType> GetData()
{
return (new MyTypeRepository()).All.ToList();
}
该配置: -
<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>
我可以通过http://localhost:1422/xxxx.svc
查看服务定义页但是我似乎无法调用方法的GetData(添加到URI的结尾 - http://localhost:1422/xxxx.svc/GetData
)
有谁知道为什么我会得到一个HTTP 400 - 错误的请求
非常感谢 特拉维斯
感谢/帮助提示Swani上述服务 - 这有助于解决问题 –
@ TravisIngram,你欢迎:)。我没有注意到“发布”和“获取”:) –