2012-10-26 3 views
0

WCF 서비스를 사용하고 "원격 서버에서 오류 (400) 요청이 잘못되었습니다."라는 오류 메시지가 나타납니다. 웹 클라이언트를 통해 소모 할 때 다음과 같이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(); 
} 

구성 : -

나는 HTTP를 얻을 왜

사람이 알고 있나요 - 나는 방법 GetData의를 호출 할 수없는 것 그러나

<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를 통해 서비스 정의 페이지를 볼 수 있습니다 (http://localhost:1422/xxxx.svc/GetData URI에의 마지막에 추가) 400 - 잘못된 요청

많은 감사 트래비스

답변

0

문제는 전적으로 내 잘못이었다 - 나는/도움말 팁 Swani에 대해 "GET"요청으로

2

같은 코드는 나를 위해 잘 작동합니다. 다음과 같이 구성 설정을 변경하십시오.

<endpointBehaviors> 
    <behavior name="MyEndpointBehavior"> 
     <webHttp helpEnabled="true" automaticFormatSelectionEnabled="true" /> 
    </behavior> 
    </endpointBehaviors> 

그리고 http://localhost:1422/xxxx.svc/help으로 서비스를 탐색하면 GetData 작업을 수행 할 수 있습니다. 이제 http://localhost:1422/xxxx.svc/GetData으로 시도해보십시오.

또한 응용 프로그램 (프로젝트) -> 속성 -> 웹 -> 특정 포트 (1422를 입력하십시오)로 이동하면 응용 프로그램이 다른 포트 (1422 이상) 이제이 탐색을 시도하십시오.

희망이 도움이됩니다.

+0

감사 계약을 체결 한 위의 서비스에 "포스트"요청을했다 -이 문제 –

+0

를 해결하는 데 도움 @ TravisIngram, 당신은 환영합니다 :). 나는 "Post"& "Get"을 알지 못했다. :) –

관련 문제