2010-11-25 3 views
1

매우 간단한 WCF 서비스를 HTTp Get과 함께 사용하려고 시도했지만 제대로 작동하지 않습니다. 우리는 그 "가이드"를 따라했지만 우리는 다음 URL에 우리의 서비스를 호출 할 때이HTTP와 함께 WCF 서비스를 사용하는 방법 (Visual studio 2010 내)

작동하지 않습니다, 우리는 페이지를 찾을 수 없습니다 오류가 발생합니다 :

http://localhost:9999/Service1.svc/GetData/ABC

기본 URL (HTTP : // localhost를 : 9999/Service1.svc)이 잘 작동하고 올바르게 WCF 서비스 정보 페이지를 반환합니다.

이 코드는 예제를 재현하는 단계와 코드입니다.

  1. 비주얼 스튜디오 2010 년, 새로운 "WCF 서비스 응용 프로그램"프로젝트
  2. 이 코드

    [ServiceContract()] 
        public interface IService1 
        { 
         [OperationContract()] 
         [WebInvoke(Method = "GET", 
           BodyStyle = WebMessageBodyStyle.Bare, 
           UriTemplate = "GetData/{value}")] 
         string GetData(string value); 
        } 
    
  3. 이 코드

    public class Service1 : IService1 
    { 
        public string GetData(string value) 
        { 
         return string.Format("You entered: {0}", value); 
        } 
    } 
    
    으로 서비스 클래스를 교체 IService 인터페이스를 교체를 만들
  4. web.config는 다음과 같습니다.

    <system.web> 
        <compilation debug="true" strict="false" explicit="true" targetFramework="4.0" /> 
    </system.web> 
    <system.serviceModel> 
        <services> 
         <service name="Service1"> 
          <endpoint address="" binding="webHttpBinding" contract="IService1" behaviorConfiguration="WebBehavior1"> 
          </endpoint> 
         </service> 
        </services> 
        <behaviors> 
         <endpointBehaviors> 
          <behavior name="WebBehavior1"> 
          <webHttp helpEnabled="True"/> 
        </behavior> 
    </endpointBehaviors> 
    <serviceBehaviors> 
    <behavior> 
        <serviceMetadata httpGetEnabled="true"/> 
        <serviceDebug includeExceptionDetailInFaults="false"/> 
        </behavior> 
    </serviceBehaviors> 
    

  5. 을 눌러 실행과 사람이 나 뭔가 비슷한 작업을 진행하면 가져 오기 방법

에게 전화를 시도, 그것은 매우 종류의 수 있다면 것 작업 예제에 대한 회신 정보.

고맙습니다.

답변

1

견본을 재창조했습니다. 매력처럼 작동합니다.

원 포인트 : .NET 네임 스페이스 내에 서비스 계약 (public interface IService1) 및 서비스 구현 (public class Service1 : IService1)이 존재합니까 ??

그래서, 당신이 당신의 *의 SVC는을 변경해야하는 경우와 web.config은 다음을 포함합니다 :

<services> 
     <service name="Namespace.Service1"> 
      <endpoint address="" binding="webHttpBinding" 
        contract="Namespace.IService1" 
        behaviorConfiguration="WebBehavior1"> 
      </endpoint> 
     </service> 
    </services> 

<service name="..."> 속성과 <endpoint contract="...">는이 작업을위한 .NET 네임 스페이스를 포함해야합니다.

+0

정말 옳습니다 ... 그것은 루트 네임 스페이스가 없기 때문입니다. 다른 바인딩에는 괜찮지 만 (루트 네임 스페이스없이) 작동하지만 webHttpBinding에서는 작동하지 않습니다. 고맙습니다. –