同一服务上的 Soap 和 Rest 返回状态 404/找不到soap端点的端点 [英] Soap and Rest on same service returns status 404/endpoint not found for soap endpoint

查看:47
本文介绍了同一服务上的 Soap 和 Rest 返回状态 404/找不到soap端点的端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为同一个服务配置两个端点,一个用于休息,即 webHttpBinding,另一个用于肥皂,即 wsHttpBinding.但是当我使用soap服务时,它没有给我找到端点.

I am trying to configure two endpoints for the same service one for rest that is webHttpBinding and one for soap that is wsHttpBinding. but when I hit the service for soap it gives me no endpoint found.

这是我的界面ITicketService.cs

Here is my interface 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)

Here is my Service Configuration (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 它为我提供了休息端点的正确数据

When I go to url http://example.com/TicketService.svc/tickets it gives me correct data for rest endpoint

当我访问 url http://example.com/TicketService.svc/soap 它给我 找不到端点.

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

so not able to create proxy for soap service.

提前感谢您抽出时间来查看我的问题.

Thanks in advance for your time to review my question.

推荐答案

我终于找到了问题,也不敢相信这个愚蠢的错误.

Hi finally I found the problem and also can't believe this silly mistake.

<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 的具体实现为目标.

In the above code snippet Service name targets Interface ITicketService which is wrong instead it should target TicketService concrete implementation.

也不用提

System.ServiceModel.Activation.WebServiceHostFactory

用于使用 SOAP 服务运行 REST 的服务标记工厂.

factory in service markup for running REST with SOAP service.

这篇关于同一服务上的 Soap 和 Rest 返回状态 404/找不到soap端点的端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆