2009-11-23 57 views
0

我想設置一個ASPX頁面來調用一個ScriptManager的WCF服務。由於某種原因,當我調用servcie的「SpinStitch.Services.Chat.IChatter.CreateChatSession」方法時,出現此錯誤「服務器方法'CreateChatSession'失敗。'我在服務器的CreateChatSession方法中設置了一個斷點,但是它從來沒有達到過這樣的程度,我不確定我設置錯了什麼,我已經看了100個樣本,如何設置它們,它們看起來都差不多。僅僅指剛諾埃的<%= ChatSessionObject%> 屬性是從後面的ASPX代碼來,並創建一個JSON序列化對象。有什麼想法?在AJAX Web應用程序中發送JSON幫助WCF servcie

Interface: 
using System.ServiceModel; 
using System.ServiceModel.Web; 
namespace SpinStitch.Services.Chat 
{ 
    [ServiceContract(Namespace = "SpinStitch.Services.Chat")] 
    public interface IChatter 
    { 

     [OperationContract] 
     bool CreateChatSession(Domain.Objects.ChatSession chat); 

    } 

} 

Service: 
using System.ServiceModel.Activation; 
using SpinStitch.Domain.Adapters; 

namespace SpinStitch.Services.Chat 
{ 
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
    public class Chatter : IChatter 
    { 

     public bool CreateChatSession(Domain.Objects.ChatSession chat) 
     { 
      return ChatSessionAdapter.CreateChatSession(chat) > 0; 
     } 
    } 

} 

Web.Config of hosted service: 
<system.serviceModel> 

    <behaviors> 
     <endpointBehaviors> 
     <behavior name="ChatBehaviorConfig"> 
      <enableWebScript/>   
     </behavior> 

     </endpointBehaviors> 
      <serviceBehaviors> 
         <behavior name="ChatBehavior"> 
      <serviceMetadata httpGetEnabled="true"/> 
      <serviceDebug includeExceptionDetailInFaults="true"/> 

     </behavior> 

      </serviceBehaviors> 
     </behaviors> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"> 
    </serviceHostingEnvironment> 

    <services> 

     <service behaviorConfiguration="ChatBehavior" name="SpinStitch.Services.Chat.Chatter"> 
     <endpoint address="http://servicesdev.spinstitch.com/Chat.svc" binding="webHttpBinding" behaviorConfiguration="ChatBehaviorConfig" bindingConfiguration="" name="Chat" contract="SpinStitch.Services.Chat.IChatter" /> 
     </service> 
     </services> 
    </system.serviceModel> 

Web Config of Ajax App: 
<system.serviceModel> 
    <bindings> 
     <customBinding> 
     <binding name="Chat"> 
      <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" 
      messageVersion="Soap12" writeEncoding="utf-8"> 
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
       maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
      </textMessageEncoding> 
     </binding> 
     </customBinding> 
      </bindings> 
    <client> 
      <endpoint binding="customBinding" bindingConfiguration="Chat" 
     contract="ServicesDevChat.IChatter" name="Chat" /> 
    </client> 
    </system.serviceModel> 


ASPX: 
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="AnonymousUser.aspx.vb" Inherits="TestArea_ChatTest_AnonymousUser" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
</head> 
<script language="javascript" type="text/javascript"> 
function pageLoad() { 
    var chatSession = <%=ChatSessionObject %> 
    SpinStitch.Services.Chat.IChatter.CreateChatSession(chatSession, OnRetrieveLoadData, failed) 
} 

function OnRetrieveLoadData(recordInserted) { 
    alert(recordInserted) 
} 

function failed(sender, e) { 
    alert(sender._message); 
} 
</script> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
     <asp:ScriptManager ID="ScriptManager1" runat="server"> 
     <Services> 
      <asp:ServiceReference Path="http://servicesdev.spinstitch.com/chat.svc" /> 
     </Services> 

     </asp:ScriptManager> 



    </div> 
    </form> 
</body> 
</html> 

回答

0

因爲服務在單獨運行主要。在.Net 3.5下,你無法跨域。感謝大家的期待!

0

它看起來並不像ChatSession是DataContract /數據成員的對象。相反,它看起來像某種純粹的腳本對象,對嗎?如果是這樣,那很可能是操作失敗的原因。

+0

實際上,它失敗了,因爲服務運行在一個單獨的域中,並且這是3.5中的No-No現在,在4.0中,您可以跨域。我會發布這個答案。 – DDiVita 2011-02-03 11:47:28