2012-10-11 2 views
1

다음과 같은 간단한 WCF 서비스가 있습니다.WCF 서비스에서 작동하지 않는 wsHttpBinding 자체 호스팅 됨. SOAP 기반 바인딩이 작동합니다.

[ServiceContract] 
public interface IService1 
{ 
    [OperationContract] 
    [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest)] 
    string GetData(int value); 
} 

public class Service1 : IService1 
{ 
    public string GetData(int value) 
    { 
     return string.Format("You entered: {0}", value); 
    } 
} 

서버 Web.config 파일이 클라이언트는 누구의 App.config이있는 콘솔 응용 프로그램

<?xml version="1.0"?> 
<configuration> 
<appSettings> 
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /> 
</appSettings> 

<system.serviceModel> 
    <behaviors> 
     <endpointBehaviors> 
      <behavior name="webHttpEndpointBehavior"> 
       <webHttp faultExceptionEnabled="true" /> 
      </behavior> 
     </endpointBehaviors> 
     <serviceBehaviors> 
      <behavior name="serviceBehaviourDebug"> 
       <!-- To avoid disclosing metadata information, set the values below to false before deployment --> 
       <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/> 
       <!-- To receive exception details in faults for debugging purposes, set the value below to true. 
        Set to false before deployment to avoid disclosing exception information --> 
       <serviceDebug includeExceptionDetailInFaults="true"/> 
      </behavior> 
     </serviceBehaviors> 
    </behaviors> 

    <services> 
     <service name="Diws.Service1" behaviorConfiguration="serviceBehaviourDebug"> 
      <endpoint 
       address="/basicHttp" 
       binding="basicHttpBinding" 
       contract="Diws.IService1"/> 
      <endpoint 
       address="/webHttp" 
       binding="webHttpBinding" 
       behaviorConfiguration="webHttpEndpointBehavior" 
       contract="Diws.IService1"/> 
      <endpoint 
       address="/wsHttp" 
       binding="wsHttpBinding" 
       contract="Diws.IService1"/> 
      <endpoint 
       address="mex" 
       binding="mexHttpBinding" 
       contract="IMetadataExchange" /> 
     </service> 
    </services> 

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> 
</system.serviceModel> 

<system.web> 
    <compilation debug="true" targetFramework="4.5" /> 
    <httpRuntime targetFramework="4.5"/> 
</system.web> 

<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    <!-- 
    To browse web app root directory during debugging, set the value below to true. 
    Set to false before deployment to avoid disclosing web app folder information. 
    --> 
    <directoryBrowse enabled="true"/> 
</system.webServer> 
</configuration> 

이다.

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
<startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> 
</startup> 

<system.serviceModel> 
    <behaviors> 
     <endpointBehaviors> 
      <behavior name="webHttpEndpointBehavior"> 
       <webHttp /> 
      </behavior> 
     </endpointBehaviors> 
    </behaviors> 

    <bindings> 
     <basicHttpBinding> 
      <binding name="BasicHttpBinding_IService1" /> 
     </basicHttpBinding> 
     <wsHttpBinding> 
      <binding name="WsHttpBinding_IService1" /> 
     </wsHttpBinding> 
     <webHttpBinding> 
      <binding name="WebHttpBinding_IService1" /> 
     </webHttpBinding> 
    </bindings> 

    <client> 
     <endpoint 
      address="http://localhost:50001/Service1.svc/basicHttp" 
      binding="basicHttpBinding" 
      bindingConfiguration="BasicHttpBinding_IService1" 
      contract="ServiceReference1.IService1" 
      name="BasicHttpEndpoint_IService1" /> 
     <endpoint 
      address="http://localhost:50001/Service1.svc/webHttp" 
      behaviorConfiguration="webHttpEndpointBehavior" 
      binding="webHttpBinding" 
      bindingConfiguration="WebHttpBinding_IService1" 
      contract="ServiceReference1.IService1" 
      name="WebHttpEndpoint_IService1" /> 
     <endpoint 
      address="http://localhost:50001/Service1.svc/wsHttp" 
      binding="wsHttpBinding" 
      bindingConfiguration="WsHttpBinding_IService1" 
      contract="ServiceReference1.IService1" 
      name="WsHttpEndpoint_IService1"/> 
    </client> 
</system.serviceModel> 

<system.web> 
    <compilation debug="true" targetFramework="4.5" /> 
    <httpRuntime targetFramework="4.5"/> 
</system.web> 
</configuration> 

클라이언트 프로그램은 다음과 같습니다.

class Program 
{ 
    static void Main(String[] args) 
    { 
     String response = ""; 

     Service1Client basicHttpClient = new Service1Client("BasicHttpEndpoint_IService1"); 
     response = basicHttpClient.GetData(10); 
     basicHttpClient.Close(); 
     Console.WriteLine(response); 

     ///* Some communication exception 
     Service1Client webHttpClient = new Service1Client("WebHttpEndpoint_IService1"); 
     response = webHttpClient.GetData(20); 
     webHttpClient.Close(); 
     Console.WriteLine(response); 
     //*/ 

     Service1Client wsHttpClient = new Service1Client("WsHttpEndpoint_IService1"); 
     response = wsHttpClient.GetData(30); 
     wsHttpClient.Close(); 
     Console.WriteLine(response); 

     Console.WriteLine(); 
     Console.WriteLine("Done"); 
     Console.ReadLine(); 
    } 
} 

basicHttpClient와 wsHttpClient가 완벽하게 작동합니다. 그러나, webHttpClient가 예외를 throw "System.ServiceModel.CommunicationException는, HRESULT = -2146233087 처리되지 않은했다, 메시지 = 내부 서버 오류"나는 비주얼 스튜디오 2012과 같은 서버 측에서 디버깅 할 수 없습니다

말한다 '자동 디버깅 "할 수 없습니다 MyProject '원격 프로 시저를 디버깅 할 수 없습니다. 일반적으로 디버깅이 서버에서 활성화되지 않았 음을 나타냅니다. "

그러나 디버깅이 사용됩니다. 진단을 켠 상태에서 SvcTraceViewer를 사용하여 통찰력을 얻을 수 없었습니다.

내 관심사는 WebHttpBinding을 사용하는 REST 호출이 실패한 이유를 파악하는 것이지만 서버 측 디버깅 작동을 얻는 것이 도움이 될 것입니다. 여러 시작 프로젝트를 사용하여 VS2012의 클라이언트와 서버를 모두 디버깅하고 있습니다. Localhost가 관련된 유일한 서버입니다.

메타 데이터 교환을 제공하지 않으므로 REST 끝점이 WcfTestClient에 표시되지 않지만 해당 끝점을 통해 서비스를 호출 할 수 있기를 기대하며 내 코드와 RESTful을 호출하는 예와의 차이가 없음을 알고 있습니다. WCF 서비스.

+0

서비스 계약이 어떻게 생겼는지 게시 할 수 있습니까? – Rajesh

답변

0

REST 끝점에 액세스하려면 URL에 브라우저 또는 HttpClient를 사용하여 HTTP POST 요청을 만드십시오. $ http : // localhost : 50001/Service1.svc/webHttp/GetData $. 코드에서 호출 할 때 webHttpClient를 사용하여 서비스를 호출하면 REST 끝점에서 처리 할 수없는 SOAP 요청을 보냅니다. 나는 이것이 당신의 다른 두 종점이 잘 작동하는 이유라고 생각하지만이 것은 아닙니다.

+0

아래 주소를 변경했습니다. 바인딩 50000/basicHttp : System.ServiceModel.BasicHttpBinding 계약 : Diws.IService1 주소 : HTTP : // localhost를 : 바인딩 50000/wsHttp 를 HTTP : // localhost를 '호스트는 엔드 포인트 주소를 시작하고있다 : 계약 System.ServiceModel.WebHttpBinding : 바인딩 50000/webHttp : Diws.IService1 주소 : HTTP : // localhost를 계약을 System.ServiceModel.WSHttpBinding Diws.IService1 주소 : HTTP : // 로컬 호스트 : 50000/mex 바인딩 : System.ServiceModel.WSHttpBinding 계약 : 시스템 m.ServiceModel.Description.IMetadataExchange [ENTER] 키를 눌러 종료하십시오. ' – Dave

+0

서비스 클래스에 '[ServiceBehavior (AddressFilterMode = AddressFilterMode.Any)]'도 추가되었습니다. 'http : // localhost : 50000/webHttp/GetData? value = 40'URL을 사용하여 웹 브라우저에서 서비스를 호출 할 때 EndpointDispatcher 예외에서 [ContractFilter mismatch]가 발생합니다 (http : // stackoverflow.com/questions/5487791/wcf-contractfilter-end-endpointdispatcher-exception에서 일치하지 않음). – Dave

+0

Visual Studio에서 생성 된 클라이언트의 서비스 프록시가 클라이언트의 구성이 서버의 구성과 일치하는 한 SOAP 기반 및 REST 기반 끝점을 모두 처리 할 수 ​​있다고 생각했습니다. 이것은 사실이 아닌가? 클라이언트 프록시는 SOAP 기반 끝점 만 처리하며 [WebClient 클래스] (http://msdn.microsoft.com/en-us/library/system.net.webclient%28v=vs.80)를 사용해야합니다. % 29.aspx) wsHttpBinding 끝점을 통해 노출 된 REST 기반 서비스에 액세스하려면? – Dave