2010-07-29 7 views
11

나는 휴식과 비누로 모두 드리고 싶은 서비스를 작성했습니다. WCF 4.0에 대해 읽은 모든 내용은이 작업을 수행하기 위해 서로 다른 동작을 가진 2 개의 끝점을 노출해야한다고 말합니다. 그러나 나는 그것을 작동시킬 수 없다.WCF 비누와 나머지 끝점을 나란히 호스팅

<?xml version="1.0"?> 
<configuration> 

    <system.web> 
     <compilation debug="true" targetFramework="4.0" /> 
    </system.web> 
    <system.serviceModel> 

     <services> 
      <service name="MyService"> 
       <endpoint name="mex" address="mex" binding="mexHttpBinding" contract="MyService"/> 
       <endpoint address="rest" behaviorConfiguration="restBehavior" binding="webHttpBinding" contract="MyService" /> 
       <endpoint address="soap" behaviorConfiguration="soapBehavior" binding="basicHttpBinding" contract="MyService" /> 
      </service> 
     </services> 

     <behaviors> 

      <serviceBehaviors> 
       <behavior> 
        <serviceMetadata httpGetEnabled="true"/> 
        <serviceDebug includeExceptionDetailInFaults="true"/> 
       </behavior> 
      </serviceBehaviors> 

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

     </behaviors> 

     <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/> 

    </system.serviceModel> 

    <system.webServer> 
     <modules runAllManagedModulesForAllRequests="true" /> 
    </system.webServer> 

</configuration> 

내 서비스 URL을 정의 할 라우팅을 사용하고 있습니다 :

public class Global : System.Web.HttpApplication 
    { 
     protected void Application_Start(object sender, EventArgs e) 
     { 
      RouteTable.Routes.Add(new ServiceRoute("dns", new ServiceHostFactory(), typeof(MyService))); 
     } 
    } 

가 여기

[ServiceContract] 
public interface MyService 
{ 
    [OperationContract] 
    [WebGet(UriTemplate="data/{value}")] 
    string GetData(string value); 
} 

내 Web.config의이다 : 여기

내 서비스 계약입니다 내가 여기서 잘못하고있는 것? 나는 약간의 도움을 정말로 사용할 수있다.

+0

나는이 다른 [질문/답] (http://stackoverflow.com/questions/186631/rest-soap-endpoints-for-a-wcf 발견 -service) 도움이됩니다. – SMB

답변

4

구성에서이 작업을 수행하는 "올바른"방법을 찾지 못했지만이를 수행하기 위해 라우팅 엔진을 사용할 수있었습니다.

내 글로벌 asax 파일은 이제 다음과 같습니다

public class Global : System.Web.HttpApplication 
    { 
     protected void Application_Start(object sender, EventArgs e) 
     { 
      RouteTable.Routes.Add(new ServiceRoute("my/soap", new ServiceHostFactory(), typeof(MyService))); 
      RouteTable.Routes.Add(new ServiceRoute("my/rest", new WebServiceHostFactory(), typeof(MyService))); 
     } 
    } 

이 같은 내 설정 : (나머지 도움말 페이지를 활성화)

<system.serviceModel> 

    <standardEndpoints> 
     <webHttpEndpoint> 
      <standardEndpoint automaticFormatSelectionEnabled="true" helpEnabled="true"/> 
     </webHttpEndpoint> 
    </standardEndpoints> 

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/> 

</system.serviceModel> 

<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true" /> 
</system.webServer> 

나는 asp.net MVC 모델에 더 가깝고 약간의 설정이 필요하다. 또한이 방법을 사용하면 내 프로젝트에서 .svc 파일을 완전히 제거 할 수있었습니다.이 프로젝트는 더하기 IMO입니다.

1

어떻게 WCF 서비스를 호스팅하고 있습니까 ?? IIS에서는 서비스 활성화를 위해 어딘가에 가상 디렉터리와 MyService.svc 파일이 필요합니다.

지금의 ServiceRoute를 제거하면 (문제를 단순화하기 위해), 당신은 귀하의 SOAP 서비스 엔드 포인트에 도달 할 수 있어야한다 :

http://YourServer:Port/YourVirtualDirectory/YourService.svc/soap 

과 REST 서비스가 있어야한다

http://YourServer:Port/YourVirtualDirectory/YourService.svc/rest/data/{value} 

에서 ({value}에 대해 임의의 값을 입력하십시오).

귀하의 경우 정확히 작동하지 않는 항목은 무엇입니까 ??

WCF Test Client을 사용하여 SOAP 끝점을 테스트하고 테스트 할 수 있지만 모든 브라우저에서 REST URL을 사용할 수 있어야합니다.

+1

IIS에서 호스팅하고 있습니다.내가 볼 문제가 루트 URL로 구성된 경우 비누 엔드 포인트 만 액세스 할 수 있는지 경우 : 어느 에 http : // yourserver를 포트/YourVirtualDirectory/YourService.svc 또는 에 http : // yourserver를 : 포트/YourVirtualDirectory/YourService (서비스 경로 사용 여부에 따라 다름). 그런 식으로 구성하면 나머지 끝점에 액세스 할 수 없습니다. 또는 원래 설명대로 구성하면 나머지 끝점에 액세스 할 수 있으며 soap 끝점에서 400 오류가 반환됩니다. – Troy

+0

완전히 새로운 서비스 파일 (.svc)을 프로젝트에 추가하려고했습니다. 위와 같은 설정을 사용하면 sorta가 작동합니다 ... .svc url에서 나머지와 비누 서비스가 제대로 작동하지만 비누 서비스는 루트에서만 액세스 할 수있었습니다. 구성된/soap 주소가 존중되지 않았습니다. – Troy

1

구성이 가능합니다. 사용자 라디 Mrnka하여 MSDN 포럼 스레드에서 : http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/4e95575f-1097-4190-80dd-7a0f96d73f6e

<system.serviceModel> 
<behaviors> 
    <endpointBehaviors> 
    <behavior name="REST"> 
     <webHttp /> 
    </behavior> 
    </endpointBehaviors> 
    <serviceBehaviors> 
    <behavior name="iSell.Prospects.ProspectBehavior"> 
     <serviceMetadata httpGetEnabled="true"/> 
     <serviceDebug includeExceptionDetailInFaults="false" /> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
<services> 
    <service behaviorConfiguration="iSell.Prospects.ProspectBehavior" name="iSell.Prospects.ProspectService"> 
    <endpoint address="" behaviorConfiguration="REST" binding="webHttpBinding" contract="iSell.Prospects.ProspectService" /> 
    <endpoint address="soap" binding="basicHttpBinding" contract="iSell.Prospects.ProspectService" /> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
    </service> 
</services> 
</system.serviceModel> 
+1

이 작업을 시도하는 사람을위한 힌트입니다. 비누 URI는 다음과 같습니다 :'http : // host/myService.svc/soap /' – dummy