在调用wcf rest service

时间:2016-08-22 17:15:09

标签: c# wcf asp.net-mvc-4 wcf-binding

我使用basicHttpBinding和webHttpBinding创建了一个带有两个不同端点的wcf服务。我有一个asp mvc客户端消耗basicHttpBinding端点和角度控制器消耗webHttpBinding。但是,当我通过浏览器和角度控制器使用webHttpBinding调用端点时,我收到连接拒绝错误。如何解决此问题或我做错了什么(WCF新手)。

服务合同:

[ServiceContract]
public interface IVacationService
{
    [WebInvoke(UriTemplate = "create",ResponseFormat = WebMessageFormat.Json)]
    [OperationContract]
    VacationDC RequestVacation(VacationDC vacation);

    [WebGet(UriTemplate = "approved",ResponseFormat = WebMessageFormat.Json)]
    [OperationContract]
    IEnumerable<VacationDC> GetApprovedVacations();

    [WebGet(UriTemplate = "all", ResponseFormat = WebMessageFormat.Json)]
    [OperationContract]
    IEnumerable<VacationDC> GetAllVacations();

    [WebInvoke(UriTemplate = "remove/{id}", Method = "DELETE",RequestFormat = WebMessageFormat.Json)]
    [OperationContract]
    void RemoveVacation(long id);
}

的Web.config:

<services>
  <service name="WcfService.VacationService">
    <endpoint address="basic" binding="basicHttpBinding" name="Soap" contract="WcfService.IVacationService" />
    <endpoint address="api"   binding="webHttpBinding" name="rest" contract="WcfService.IVacationService" behaviorConfiguration="webRest"/>
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8092/vacation" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <endpointBehaviors>
    <behavior name="webRest">
      <webHttp />
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>

0 个答案:

没有答案