我正在使用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,你歡迎:)。我沒有注意到「發佈」和「獲取」:) –