SOAP和REST在相同的服务返回状态404 /找不到肥皂端点端点(Soap and Rest on

2019-10-21 02:36发布

我想配置两个端点相同的服务一个休息是的WebHttpBinding,一个用于肥皂是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" />

当我去的URL http://example.com/TicketService.svc/tickets它给我休息端点正确的数据

当我去的URL http://example.com/TicketService.svc/soap它给我端点未找到。

所以无法为SOAP服务创建代理。

在此先感谢您的时间来审查我的问题。

Answer 1:

你好终于我发现这个问题,也不能相信这个愚蠢的错误。

<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这是错误的,而不是它的目标应票务具体实施。

而且也没有必要提及

System.ServiceModel.Activation.WebServiceHostFactory

工厂服务标记与SOAP服务运行REST。



文章来源: Soap and Rest on same service returns status 404/endpoint not found for soap endpoint