0
我想配置两个端点为同样的服务一休息是webHttpBinding和一个肥皂是wsHttpBinding。但是当我打开肥皂服务时,它没有找到终点。肥皂和休息在相同的服务返回状态404 /端点没有找到肥皂端点
这里是我的接口 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它给了我端点没有发现其他端点正确的数据。
因此无法为肥皂服务创建代理。
在此先感谢您的时间来审查我的问题。
我认为这个问题可能与你的.svc文件中的标记有关。 'System.ServiceModel.Activation.WebServiceHostFactory'用于RESTful WCF,我不知道它是否会支持SOAP。您是否尝试过使用'System.ServiceModel.Activation.ServiceHostFactory'来代替? – Tim 2014-10-08 06:26:08
@Tim是的,如果我删除System.ServiceModel.Activation.WebServiceHostFactory,那么它对SOAP工作正常,但停止工作休息。所以现在我将尝试使用System.ServiceModel.Activation.ServiceHostFactory更改它。谢谢你的帮助。 – 2014-10-08 06:58:26
@Tim我曾尝试“System.ServiceModel.Activation.ServiceHostFactory”,但它只适用于肥皂和REST停止工作。你知道任何应该同时适用于SOAP和REST的工厂吗? – 2014-10-10 04:46:31