2011-04-22 42 views
11

Cho đến bây giờ tôi đã sử dụng các dịch vụ Web và nó hoạt động tốt. Tôi đã thêm một dịch vụ WCF mới.
Tôi đang gọi các dịch vụ bằng jQuery. Đây là cách tôi sử dụng jQuery để tiêu thụ các dịch vụ Web:Tiêu thụ dịch vụ WCF bằng cách sử dụng jQuery

$.ajax({ 
    dataType: 'json', 
    processData: false, 
    type: 'POST', 
    contentType: "application/json", 
    url: url, 
    context: s.context, 
    data: JSON.stringify(s.data), 
    error: function (xhr, textStatus, errorThrown) { 
     if (s.error != null) { 
      s.error(xhr, textStatus, errorThrown); 
     } 
     if (s.error_addition != null) { 
      s.error_addition(xhr, textStatus, errorThrown); 
     } 
    }, 
    success: function (data, textStatus, xhr) { 
     s.success(data.d, textStatus, xhr); 
     subscriber.setDone(data.d); 
    } 
}); 

Tôi không thể sử dụng phương pháp này để tiêu thụ dịch vụ WCF. Đây là cách dịch vụ WCF được xác định:

[ServiceContract] 
public interface ISystemService 
{  
    [OperationContract] 
    [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] 
    Reason[] GetCallReasons(); 
} 

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
public class SystemService : SimTaskService, ISystemService 
{ 
    public Reason[] GetCallReasons() 
    { 
     //... 
    } 
} 

Tôi không thêm gì vào cấu hình web cho dịch vụ WCF.

Sử dụng cáy, đây là tiêu đề phản ứng:

HTTP/1.1 415 Cannot process the message because the content type 'application/x-www-form-urlencoded' was not the expected type 'text/xml; charset=utf-8'. 

Dưới đây là web.config của tôi:

<?xml version="1.0"?> 
<configuration> 
    <configSections> 
    <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> 
     <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> 
     <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /> 
     <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> 
      <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" /> 
      <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /> 
      <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /> 
      <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /> 
     </sectionGroup> 
     </sectionGroup> 
    </sectionGroup> 
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > 
     <section name="MyProj.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    </sectionGroup> 
    </configSections> 
    <connectionStrings> 
    <clear /> 
    <add name="MyProj" connectionString="Data Source=lololo;Initial Catalog=MyProj;User ID=sa;Password=12345;" providerName="System.Data.SqlClient" /> 
    </connectionStrings> 
    <system.web> 
    <authentication mode="Forms"> 
     <forms name="MyProjAuthentication" loginUrl="~/Login.aspx" timeout="720" slidingExpiration="true" /> 
    </authentication> 
    <authorization> 
     <deny users="?" /> 
     <allow users="*" /> 
    </authorization> 
    <compilation debug="true" defaultLanguage="c#"> 
     <assemblies> 
     <add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /> 
     <add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /> 
     <add assembly="System.Security, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /> 
     <add assembly="System.Management, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /> 
     <add assembly="System.Messaging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /> 
     <add assembly="System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /> 
     <add assembly="System.Configuration.Install, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /> 
     <add assembly="Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /> 
     <add assembly="Microsoft.ReportViewer.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /> 
     <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /> 
     <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
     <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /> 
     <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /> 
     <add assembly="WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
     <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 
     </assemblies> 
    </compilation> 
    <customErrors mode="Off"> 
    </customErrors> 
    <pages> 
     <controls> 
     <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
     <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
     </controls> 
    </pages> 
    <httpHandlers> 
     <remove verb="*" path="*.asmx" /> 
     <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
     <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
     <add verb="GET,HEAD" path="ScriptResource.axd" validate="false" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
    </httpHandlers> 
    <httpModules> 
     <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
    </httpModules> 
    <httpRuntime maxRequestLength="1048576" /> 
    </system.web> 
    <system.web.extensions> 
    <scripting> 
     <webServices> 
     <jsonSerialization maxJsonLength="99999999"> 
      <converters> 
      <add type="MyLibrary.MySystem.Json.JavaScriptConverters.NoteCustomFieldsDataJavaScriptConverter" name="NoteCustomFieldsDataJavaScriptConverter" /> 
      <add type="MyLibrary.MySystem.Json.JavaScriptConverters.WarehouseCustomFieldsJavaScriptConverter" name="WarehouseCustomFieldsJavaScriptConverter" /> 
      <add type="MyLibrary.MySystem.Json.JavaScriptConverters.DateTimeConverter" name="DateTimeJavaScriptConverter" /> 
      </converters> 
     </jsonSerialization> 
     </webServices> 
    </scripting> 
    </system.web.extensions> 
    <system.codedom> 
    <compilers> 
     <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4"> 
     <providerOption name="CompilerVersion" value="v3.5" /> 
     <providerOption name="WarnAsError" value="false" /> 
     </compiler> 
     <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4"> 
     <providerOption name="CompilerVersion" value="v3.5" /> 
     <providerOption name="OptionInfer" value="true" /> 
     <providerOption name="WarnAsError" value="false" /> 
     </compiler> 
    </compilers> 
    </system.codedom> 
    <system.webServer> 
    <validation validateIntegratedModeConfiguration="false" /> 
    <modules> 
     <remove name="ScriptModule" /> 
     <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
    </modules> 
    <handlers> 
     <remove name="WebServiceHandlerFactory-Integrated" /> 
     <remove name="ScriptHandlerFactory" /> 
     <remove name="ScriptHandlerFactoryAppServices" /> 
     <remove name="ScriptResource" /> 
     <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
     <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
     <add name="ScriptResource" verb="GET,HEAD" path="ScriptResource.axd" preCondition="integratedMode" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
    </handlers> 
    </system.webServer> 
    <runtime> 
    <assemblyBinding appliesTo="v2.0.50727" xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
    <system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name=""> 
      <serviceMetadata httpGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="false" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" 
     multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
</configuration> 

Có ai biết làm thế nào để sửa chữa nó?

+0

Câu hỏi đặt ra là tại sao bạn có được hình thức bài thay vì bài đăng json với kiểu nội dung 'application/json'. Ngoài ra tại sao bạn đăng dữ liệu khi hoạt động của bạn không mong đợi bất kỳ thông số đầu vào nào? –

+0

@Ladislav Mrnka: Đây là một phương pháp chung. dữ liệu thực sự là đối tượng trống. "Json post" là gì? – Naor

+0

@Naro: Mã bưu điện của web.config –

Trả lời

4

Tôi đã sử dụng hướng dẫn this d nó làm việc tuyệt vời.
bởi vì tôi đang sử dụng asp.net với WCF, tôi đã cần thiết để thêm:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 

như một thuộc tính với dịch vụ đẳng cấp.
Ngoài ra thêm dòng này vào web.config:

<serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> 

Hope this helps!

+2

Chế độ tương thích với ASP.NET không liên quan gì đến vấn đề này và không cần thiết để nhận dịch vụ WCF hoạt động. Nó chỉ quan trọng nếu bạn đang viết dịch vụ WCF của bạn phụ thuộc vào đường dẫn ASP.NET, tức là 'HttpContext' hoặc trạng thái phiên. – Aaronaught

0

Hãy thử thêm này vào cấu hình WCF của bạn:

<?xml version="1.0" encoding="utf-8"?> 
<system.serviceModel> 
    <service behaviorConfiguration="DefaultWcfServiceBehavior" name="Your.Namespace.SystemService "> 
    <endpoint contract="Your.Namespace.Contract.ISystemService " 
     binding="webHttpBinding" behaviorConfiguration="JsonBehavior"> 
    </endpoint> 
    </service> 

    <bindings> 
    <basicHttpBinding> 
     <binding name="BasicHttpEndpointBinding" receiveTimeout="00:20:00" maxReceivedMessageSize="2000000000"> 
     <security mode="TransportCredentialOnly"> 
      <transport clientCredentialType="Windows" /> 
     </security> 
     </binding> 
    </basicHttpBinding> 
    </bindings> 

    <behaviors> 
    <endpointBehaviors> 
     <behavior name="JsonBehavior"> 
     <enableWebScript/> 
     </behavior> 
    </endpointBehaviors> 
    <serviceBehaviors> 
     <behavior name="DefaultWcfServiceBehavior"> 
     <serviceMetadata httpGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="true" /> 
     </behavior> 
    </serviceBehaviors> 
    </behaviors> 

</system.serviceModel> 

Ngoài ra, đây là từ những gì tôi đã làm việc trong ứng dụng của chúng tôi ở đây:

$.ajax({ 
     url: systemServiceURL, 
     data: JSON.stringify(data), 
     type: "POST", 
     processData: true, 
     contentType: "application/json", 
     timeout: 10000, 
     dataType: "json", 
     beforeSend: function(req) { 
      req.setRequestHeader('Authorization','Basic <encryptedAuthorization>');     
     }, 
     success: function(msg) {     
      //do stuff here 
     }, 
     error: function(msg) { 
      alert('error : ' + msg.d); 
     } 
    }); 

EDIT: Đã cố gắng sửa đổi web.config sửa vào Câu hỏi :

<?xml version="1.0"?> 
<configuration> 
    <configSections> 
    <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> 
     <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> 
     <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /> 
     <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> 
      <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" /> 
      <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /> 
      <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /> 
      <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /> 
     </sectionGroup> 
     </sectionGroup> 
    </sectionGroup> 
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > 
     <section name="MyProj.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    </sectionGroup> 
    </configSections> 
    <connectionStrings> 
    <clear /> 
    <add name="MyProj" connectionString="Data Source=lololo;Initial Catalog=MyProj;User ID=sa;Password=12345;" providerName="System.Data.SqlClient" /> 
    </connectionStrings> 
    <system.web> 
    <authentication mode="Forms"> 
     <forms name="MyProjAuthentication" loginUrl="~/Login.aspx" timeout="720" slidingExpiration="true" /> 
    </authentication> 
    <authorization> 
     <deny users="?" /> 
     <allow users="*" /> 
    </authorization> 
    <compilation debug="true" defaultLanguage="c#"> 
     <assemblies> 
     <add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /> 
     <add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /> 
     <add assembly="System.Security, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /> 
     <add assembly="System.Management, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /> 
     <add assembly="System.Messaging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /> 
     <add assembly="System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /> 
     <add assembly="System.Configuration.Install, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /> 
     <add assembly="Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /> 
     <add assembly="Microsoft.ReportViewer.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /> 
     <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /> 
     <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
     <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /> 
     <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /> 
     <add assembly="WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
     <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 
     </assemblies> 
    </compilation> 
    <customErrors mode="Off"> 
    </customErrors> 
    <pages> 
     <controls> 
     <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
     <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
     </controls> 
    </pages> 
    <httpHandlers> 
     <remove verb="*" path="*.asmx" /> 
     <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
     <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
     <add verb="GET,HEAD" path="ScriptResource.axd" validate="false" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
    </httpHandlers> 
    <httpModules> 
     <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
    </httpModules> 
    <httpRuntime maxRequestLength="1048576" /> 
    </system.web> 
    <system.web.extensions> 
    <scripting> 
     <webServices> 
     <jsonSerialization maxJsonLength="99999999"> 
      <converters> 
      <add type="MyLibrary.MySystem.Json.JavaScriptConverters.NoteCustomFieldsDataJavaScriptConverter" name="NoteCustomFieldsDataJavaScriptConverter" /> 
      <add type="MyLibrary.MySystem.Json.JavaScriptConverters.WarehouseCustomFieldsJavaScriptConverter" name="WarehouseCustomFieldsJavaScriptConverter" /> 
      <add type="MyLibrary.MySystem.Json.JavaScriptConverters.DateTimeConverter" name="DateTimeJavaScriptConverter" /> 
      </converters> 
     </jsonSerialization> 
     </webServices> 
    </scripting> 
    </system.web.extensions> 
    <system.codedom> 
    <compilers> 
     <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4"> 
     <providerOption name="CompilerVersion" value="v3.5" /> 
     <providerOption name="WarnAsError" value="false" /> 
     </compiler> 
     <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4"> 
     <providerOption name="CompilerVersion" value="v3.5" /> 
     <providerOption name="OptionInfer" value="true" /> 
     <providerOption name="WarnAsError" value="false" /> 
     </compiler> 
    </compilers> 
    </system.codedom> 
    <system.webServer> 
    <validation validateIntegratedModeConfiguration="false" /> 
    <modules> 
     <remove name="ScriptModule" /> 
     <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
    </modules> 
    <handlers> 
     <remove name="WebServiceHandlerFactory-Integrated" /> 
     <remove name="ScriptHandlerFactory" /> 
     <remove name="ScriptHandlerFactoryAppServices" /> 
     <remove name="ScriptResource" /> 
     <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
     <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
     <add name="ScriptResource" verb="GET,HEAD" path="ScriptResource.axd" preCondition="integratedMode" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
    </handlers> 
    </system.webServer> 
    <runtime> 
    <assemblyBinding appliesTo="v2.0.50727" xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
    <system.serviceModel> 
    <services> 
     <service behaviorConfiguration="DefaultWcfServiceBehavior" name="Your.Namespace.SystemService "> 
     <endpoint contract="Your.Namespace.Contract.ISystemService " 
      binding="webHttpBinding" behaviorConfiguration="JsonBehavior"> 
     </endpoint> 
     </service> 
    </services> 
    <bindings> 
    <basicHttpBinding> 
     <binding name="BasicHttpEndpointBinding" receiveTimeout="00:20:00" maxReceivedMessageSize="2000000000"> 
     <security mode="TransportCredentialOnly"> 
      <transport clientCredentialType="Windows" /> 
     </security> 
     </binding> 
    </basicHttpBinding> 
    </bindings> 
    <behaviors> 
     <endpointBehaviors> 
      <behavior name="JsonBehavior"> 
      <enableWebScript/> 
      </behavior> 
     </endpointBehaviors> 
     <serviceBehaviors> 
      <behavior name="DefaultWcfServiceBehavior"> 
       <serviceMetadata httpGetEnabled="true" /> 
       <serviceDebug includeExceptionDetailInFaults="true" /> 
      </behavior> 
      <behavior name=""> 
       <serviceMetadata httpGetEnabled="true" /> 
       <serviceDebug includeExceptionDetailInFaults="false" /> 
      </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" 
     multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
</configuration> 
+0

Cấu hình WCF là gì? Tôi đang sử dụng ứng dụng web asp.NET. Vui lòng xem cập nhật - Tôi nghĩ rằng tôi đã tìm ra sự cố. – Naor

+0

Đối với iis lưu trữ WCF 'web.config' sẽ là nơi bạn sẽ có các cấu hình WCF –

+0

Tôi đăng mã web.config. Bạn có thể giải thích nơi tôi nên sửa chữa nó và làm thế nào? – Naor

0

Bạn cần phải xác định rằng dịch vụ yên tĩnh sẽ tiêu thụ một đối tượng JSON

Liên kết này sẽ giúp http://www.codeproject.com/KB/ajax/jQueryWCFRest.aspx

Thay đổi cấu hình:

<endpointBehaviors> 
    <behavior name="jsonBehavior"> 
    <enableWebScript/> 
    </behavior> 
</endpointBehaviors> 
Các vấn đề liên quan