2014-10-08 60 views
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它給了我端點沒有發現其他端點正確的數據。

因此無法爲肥皂服務創建代理。

在此先感謝您的時間來審查我的問題。

+0

我認爲這個問題可能與你的.svc文件中的標記有關。 'System.ServiceModel.Activation.WebServiceHostFactory'用於RESTful WCF,我不知道它是否會支持SOAP。您是否嘗試過使用'System.ServiceModel.Activation.ServiceHostFactory'來代替? – Tim 2014-10-08 06:26:08

+0

@Tim是的,如果我刪除System.ServiceModel.Activation.WebServiceHostFactory,那麼它對SOAP工作正常,但停止工作休息。所以現在我將嘗試使用System.ServiceModel.Activation.ServiceHostFactory更改它。謝謝你的幫助。 – 2014-10-08 06:58:26

+0

@Tim我曾嘗試「System.ServiceModel.Activation.ServiceHostFactory」,但它只適用於肥皂和REST停止工作。你知道任何應該同時適用於SOAP和REST的工廠嗎? – 2014-10-10 04:46:31

回答

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這是錯誤的,而不是它的目標應票務具體實施。

而且也沒有必要提及

System.ServiceModel.Activation.WebServiceHostFactory 

廠服務標記與SOAP服務運行REST。