同一服务上的Soap和Rest返回状态404 /找不到soap端点的端点

时间:2014-10-08 03:26:36

标签: c# wcf rest soap wcf-binding

我正在尝试为同一服务配置两个端点,一个用于webHttpBinding,一个用于soap,即wsHttpBinding。但当我点击肥皂服务时,它没有找到任何终点。

这是我的界面 ITicketService.cs

[ServiceContract]
public interface ITicketService
{

    [OperationContract]
    [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json,
        ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "/tickets")]
    void AddTicket(Ticket ticket);

    [OperationContract]
    [WebInvoke(Method = "GET",
        ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "/tickets")]
    IQueryable<Ticket> GetAllTickets();

    [OperationContract]
    [WebInvoke(Method = "GET",
        ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "/tickets/{id}")]
    Ticket GetTicketById(string id);

    [OperationContract]
    [WebInvoke(Method = "GET",
        ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "/tickets/show_many?ids={ids}")]
    IQueryable<Ticket> GetSeveralTicketsById(string ids);

    [OperationContract]
    [WebInvoke(Method = "PUT", RequestFormat = WebMessageFormat.Json,
        ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "/tickets/{ticket_id}")]
    void UpdateTicket(Ticket ticket, string ticket_id);
}

这是票务服务标记

<%@ ServiceHost Language="C#" Debug="true" Service="TicketSupportSystem.Rest.Service.TicketService" 
Factory="System.ServiceModel.Activation.WebServiceHostFactory" CodeBehind="TicketService.svc.cs" %>

这是我的实际服务实现

public class TicketService : ITicketService
{
    TicketManager _ticketManager = new TicketManager();
    public void AddTicket(Ticket ticket)
    {
        _ticketManager.InsertTicket(ticket);
    }

    public IQueryable<Ticket> GetAllTickets()
    {
        return _ticketManager.GetAllTickets();
    }

    public Ticket GetTicketById(string id)
    {
        int ticketId = Convert.ToInt16(id);
        return _ticketManager.GetTicketById(ticketId);
    }

    public IQueryable<Ticket> GetSeveralTicketsById(string ids)
    {
        var idList = ids.Split(',');
        List<Ticket> tickets = new List<Ticket>();
        foreach (var item in idList)
        {
            tickets.Add(GetTicketById(item));
        }
        return tickets.AsQueryable();
    }

    public void UpdateTicket(Ticket ticket, string ticket_id)
    {
        int ticketId = Convert.ToInt16(ticket_id);
        ticket.Id = ticketId;
        _ticketManager.UpdateTicket(ticket);
    }

}

这是我的服务配置(web.config)

<system.serviceModel>
<bindings>
  <wsHttpBinding>
    <!-- or WsHttpBinding -->
    <binding name="wsHttpBinding" >
      <security mode="Transport">
        <transport clientCredentialType="Ntlm" proxyCredentialType="Ntlm" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
<services>
  <service name="TicketSupportSystem.Rest.Service.ITicketService" behaviorConfiguration="ServiceBehaviour">
    <endpoint name="restTicketService" address="web" binding="webHttpBinding" contract="TicketSupportSystem.Rest.Service.ITicketService"  behaviorConfiguration="web">
    </endpoint>
    <endpoint name="soapTicketService" address="soap" binding="wsHttpBinding" contract="TicketSupportSystem.Rest.Service.ITicketService" >
    </endpoint>
  </service>
  <service name="TicketSupportSystem.Rest.Service.ITicketCommentService"  behaviorConfiguration="ServiceBehaviour">
    <endpoint address="" binding="webHttpBinding" contract="TicketSupportSystem.Rest.Service.ITicketCommentService"  behaviorConfiguration="web">
    </endpoint>
    <endpoint address="" binding="wsHttpBinding" contract="TicketSupportSystem.Rest.Service.ITicketCommentService"  >
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

  </service>
  <service name="TicketSupportSystem.Rest.Service.IUserIdentityService"  behaviorConfiguration="ServiceBehaviour">
    <endpoint address="" binding="webHttpBinding" contract="TicketSupportSystem.Rest.Service.IUserIdentityService"  behaviorConfiguration="web">
    </endpoint>
    <endpoint address="" binding="wsHttpBinding" contract="TicketSupportSystem.Rest.Service.IUserIdentityService" >
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

  </service>

</services>
<behaviors>
  <endpointBehaviors>
    <behavior name="web">
      <enableWebScript/>
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehaviour">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment  multipleSiteBindingsEnabled="true" />

当我转到网址 http://example.com/TicketService.svc/tickets 时,它会为我提供正确的休息端点数据

当我转到网址 http://example.com/TicketService.svc/soap 时,它会给我端点找不到。

因此无法为soap服务创建代理。

提前感谢您抽出时间审核我的问题。

1 个答案:

答案 0 :(得分:0)

嗨,我终于找到了问题,也无法相信这个愚蠢的错误。

<service name="TicketSupportSystem.Rest.Service.ITicketService" behaviorConfiguration="ServiceBehaviour">
<endpoint name="restTicketService" address="web" binding="webHttpBinding" contract="TicketSupportSystem.Rest.Service.ITicketService"  behaviorConfiguration="web">
</endpoint>
<endpoint name="soapTicketService" address="soap" binding="wsHttpBinding" contract="TicketSupportSystem.Rest.Service.ITicketService" >
</endpoint>

在上面的代码片段中,服务名称的目标是接口ITicketService,而不是它应该针对TicketService的具体实现。

也无需提及

System.ServiceModel.Activation.WebServiceHostFactory

工厂服务标记,用于使用SOAP服务运行REST。