2017-10-29 2 views
0

Windows 응용 프로그램에서 자체 호스팅되는 REST 서비스를 확인하기위한 샘플 데스크톱 응용 프로그램을 만들었습니다. 여기 내 샘플 Windows 응용 프로그램에서 WCF elf Hosted Service

public class PayMentService : IPayMentService 
{ 
    public string PayBill() 
    { 
     return "Transaction having PayId 12 was successful"; 
    } 
} 

[ServiceContract] 
public interface IPayMentService 
{ 
    [OperationContract] 
    [WebInvoke(Method = "GET", UriTemplate = "/PayBill", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] 
    string PayBill(); 

} 

입니다 그리고 내 구성 파일은

<configuration> 
    <system.serviceModel> 
    <behaviors> 
     <endpointBehaviors> 
     <behavior name="JsonBehavior"> 
      <webHttp /> 
     </behavior> 
     </endpointBehaviors> 
     <serviceBehaviors> 
     <behavior name=""> 
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="false" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <services> 
     <service name="SelfHostedWCFService.WCFService"> 
     <endpoint address="" behaviorConfiguration="JsonBehavior" binding="webHttpBinding" 
      contract="SelfHostedWCFService.IWCFService" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost:8785" /> 
      </baseAddresses> 
     </host> 
     </service> 
     <service name="SelfHostedWCFService.WCFCheck"> 
     <endpoint address="" binding="basicHttpBinding" contract="SelfHostedWCFService.IWCFCheck"> 
      <identity> 
      <dns value="localhost" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost:8733/Design_Time_Addresses/SelfHostedWCFService/WCFCheck/" /> 
      </baseAddresses> 
     </host> 
     </service> 
     <service name="SelfHostedWCFService.PayMentService"> 
     <endpoint address="" binding="basicHttpBinding" contract="SelfHostedWCFService.IPayMentService"> 
      <identity> 
      <dns value="localhost" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost:8733/Design_Time_Addresses/SelfHostedWCFService/PayMentService/" /> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    </system.serviceModel> 
</configuration> 

처럼 그리고 난 내가의 도움으로 내 서비스를 호출하려고

static void Main() 
    { 
     ServiceHost host = new ServiceHost(typeof(SelfHostedWCFService.PayMentService)); 
     host.Open(); 
     Application.EnableVisualStyles(); 
     Application.SetCompatibleTextRenderingDefault(false); 
     Application.Run(new Form1()); 
    } 

같은 구성 URL에 호스팅 URL http://localhost:8785/service/PayMentService/PayBill. 그러나 실패했습니다. 나는 서비스가 작동하고 내 PayMentService 생성자에서 내 요청을 잡을 수 있지만 내 PayBill() 함수를 실행할 수 없다는 것을 알고 있습니다. 나는 다른 옵션을 시도했지만 아무것도 작동하지 않습니다. 누군가 조언을 해줄 수 있습니까? ..?

미리 감사

답변

1

에 나는 URL http://localhost:8785/service/PayMentService/PayBill의 도움으로 내 서비스를 호출했습니다. 그러나 실패했습니다. 기본적으로 해제되어있는 메타 데이터 검색을 활성화해야합니다. 거의 존재하고 누락 된 항목은

메타 서비스 동작 implementaion에 이름을 지정하십시오.

<serviceBehaviors> 
     <behavior name="metadataDiscovery"> 
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="false" /> 
     </behavior> 
     </serviceBehaviors> 

결제 서비스에 추가하십시오.

<service name="SelfHostedWCFService.PayMentService" behaviorConfiguration="metadataDiscovery"> 
     <endpoint address="" binding="basicHttpBinding" contract="SelfHostedWCFService.IPayMentService"> 
      <identity> 
      <dns value="localhost" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 

이제 wsdl, http://localhost:8733/Design_Time_Addresses/SelfHostedWCFService/PayMentService/을 검색 할 수 있습니다. 마찬가지로 행동 태그 구성을 모든 서비스 이름 태그에 추가하십시오.

또한 생성자가 디버그 모드에서 작동한다고 설명했지만 코드에 누락 된 사항은 거의 없습니다.

자세한 내용은 http://www.c-sharpcorner.com/UploadFile/0c1bb2/creating-wcf-rest-service/을 참조하십시오.