2011-11-02 3 views
1

WCF REST 서비스가 작동하지 않는 것 같습니다 - 구성 문제가 있습니까?

다음과 같은 서비스 계약을 통해 IIS (개발 중 IIS 익스프레스)에서 호스팅되는 사용자 지정 Y 인딩 WCF 서비스가 있습니다.

[ServiceContract] 
public interface IServer 
{ 
    [OperationContract] 
    StreamCollection GetStreams(Guid poolKey); 

    [OperationContract] 
    PoolCollection GetPools(); 

    [OperationContract] 
    StreamEntity GetStream(Guid poolKey, string localIndex);  
} 

클라이언트에서 잘 작동하며 WCFTestClient에서 메타 데이터가 확인되었습니다.
그 기능을 REST로 노출시켜야하므로 아래와 같이 새로운 계약을 만들었습니다.

동일한 서비스 클래스에서 두 인터페이스를 모두 구현했습니다.

<behaviors> 
    <endpointBehaviors> 
    <behavior name="webHttp"> 
     <webHttp/> 
    </behavior> 
    </endpointBehaviors> 
</behaviors> 
<bindings> 
    <customBinding> 
    <binding name="CustomBinding"> 
     <binaryMessageEncoding /> 
     <httpTransport maxReceivedMessageSize="655360" /> 
    </binding> 
    </customBinding> 
</bindings> 
<services> 
    <service behaviorConfiguration="ServiceBehavior" name="MyServ.Server.Server"> 
    <endpoint address="" binding="customBinding" bindingConfiguration="CustomBinding" contract="MyServ.Server.IServer" /> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
    <endpoint address="rest" behaviorConfiguration="webHttp" binding="webHttpBinding" contract="MyServ.Server.IRestServer" /> 
    </service> 
</services> 

하지만, 나머지를 사용하여 서비스에 액세스 할 때

http://localhost:<myport>/Service.svc/pools 
http://localhost:<myport>/Service.svc/pool/somekey/streams 
http://localhost:<myport>/Service.svc/pool/somekey/streams 

와 같은 URL을 사용하면 오류 404가 발생합니다.

일부 메서드와 IIS 프로세스에 연결된 디버거를 가리 키지 만 아무 것도 호출되지 않는 것 같습니다.

WCFTestClient를 사용하여 서비스 메타 데이터를 확인하면 IRestService가 아닌 IService 만 보입니다. 이게 정상인가? EDIT : 네, 보이는 것입니다 (check this)

어떤 제안 주셔서 감사합니다.

+0

난 당신 같은 서비스는 모두 인터페이스를 구현 있으리라 믿고있어 ... 하나 Responsibility는 원칙을 준수, 처음부터이 방법을 사용 하는가? –

+0

예. 이 접근 방식에 문제가있을 수 있습니까? – bzamfir

+0

둘 다 구현되지 않았다면 문제가있을 것이라고 제안하려고했습니다. :) –

답변

1

모든 제안을 주셔서 감사합니다. 그러나 마침내 문제가 해결되었습니다.

문제는 무엇이 문제인지 아직 알지 못하지만 다른 명확한 방식으로 결정했습니다.내가 한 그래서

, 나는 나머지 방법을

을 구현 RestServer을, 다른 서비스 SVC 파일을 만들 수 있었고, 난 두 개의 서로 다른 서비스, 원래 하나 (순수 WCF을 가지고 웹 설정에서 설정을 수정) 그리고 나머지 하나는 다음과 같습니다.

<service name="MyServ.Server.RestServer" > 
    <endpoint address="" name="RESTEndpoint" behaviorConfiguration="webHttp" binding="webHttpBinding" contract="MyServ.Server.IRestServer" /> 
</service> 

그리고이 트릭을했습니다.

사실, 난

3

REST 엔드 포인트는 WCFTestClient에서 사용할 수있는 방식으로 메타 데이터를 노출하지 않으므로 사용자가 액세스 할 수없는 이유가 설명됩니다. 당신은 "휴식"로 REST 엔드 포인트에 대한 엔드 포인트 주소를 지정하기 때문에 그리고 당신은 탐색중인 주소가 올바르지 않습니다, 당신은

http://localhost:port/Service.svc/rest/pool/myPoolKey/streams 
http://localhost:port/Service.svc/rest/pools 
http://localhost:port/Service.svc/rest/myPoolKey/stream/1 

처럼 뭔가 다른 일을 그들에게 접근 할 필요가 다음 [OperationContract] 속성에 Name 속성을 REST 엔드 포인트는 중요하지 않으므로 삭제할 수 있습니다 (그래도 문제가되지는 않습니다). 당신이 .NET 4.0을 사용하는 경우 또한, 당신은 당신의 인터페이스가

[ServiceContract] 
public interface IRestServer 
{ 
    [WebGet(UriTemplate = "pool/{poolKey}/streams")] 
    StreamCollection GetStreams(string poolKey); 

    [WebGet(UriTemplate = "pools")] 
    PoolCollection GetPools(); 

    [WebGet(UriTemplate = "pool/{poolKey}/stream/{localIndex}")] 
    StreamEntity GetStream(string poolKey, string localIndex); 
} 
1

로 정의 할 수 있도록 게시 할 수 당신은 이미 [WebGet]을 가지고 주어진, 전혀 [OperationContract] 속성을 필요가 없습니다 당신의 WCF 서비스를 호출하는 방법에 대한 코드? 요즘에는 클라이언트 응용 프로그램이 HTTP GET 대신 HTTP POST를 사용하여 페이지를 호출하여 404 오류가 발생하는 비슷한 문제가있었습니다. 서비스가이가 있거나하지만 서비스 계약을 구현하는 서비스는이 속성이 있는지 확인하지 않을 경우

[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/GuessWhat")] 

[WebGet(UriTemplate = "/GuessWhat/{variable}", ResponseFormat = WebMessageFormat.Json)] 

대 임 확실하지.

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
+0

http : // localhost : 51996/RestServer.svc/streams/b639dffc-9198-4c0a-85f8-d66b1c11eb6a/lasttimestamp와 같이 간단한 UR1로 서비스를 호출합니다. – bzamfir