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() 함수를 실행할 수 없다는 것을 알고 있습니다. 나는 다른 옵션을 시도했지만 아무것도 작동하지 않습니다. 누군가 조언을 해줄 수 있습니까? ..?
미리 감사