Jquery WCF-我无法在新的Web服务中找到我的方法
我已经做了一个简单的WCF服务,但是我无法接触到服务中的方法。这与CRO域问题有关 我已经试过selveral帖子和教程,但它很简单,不起作用 当我尝试访问CreateUser方法时,它返回一个“不允许的方法” 除了上面的-服务器是一个远程服务器,我可以访问设置 阿贾克斯邮报Jquery WCF-我无法在新的Web服务中找到我的方法,jquery,wcf,Jquery,Wcf,我已经做了一个简单的WCF服务,但是我无法接触到服务中的方法。这与CRO域问题有关 我已经试过selveral帖子和教程,但它很简单,不起作用 当我尝试访问CreateUser方法时,它返回一个“不允许的方法” 除了上面的-服务器是一个远程服务器,我可以访问设置 阿贾克斯邮报 <script type="text/javascript"> function createUser() { var user = {}; user.Usern
<script type="text/javascript">
function createUser() {
var user = {};
user.Username = $("[id*=userName_input]").val();
user.Password = $("[id*=userPass_input]").val();
user.Country = $("[id*=userCountry_input]").val();
user.Email = $("[id*=userEmail_input]").val();
$.ajax({
type: "POST",
url: "[url]/AttService.svc/CreateUser",
data: JSON.stringify(user),
contentType: "application/json; charset=utf-8",
dataType: "json",
processData: false,
success: function (response) {
alert("User has been added successfully.");
window.location.reload();
}
});
return false;
}
</script>
接口
<%@ ServiceHost Language="C#" Debug="true" Service="AttenttoWcfService.AttenttoService" CodeBehind="AttService.svc.cs" Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory"%>
namespace AttenttoWcfService
{
[ServiceContract(Namespace = "JsonpAjaxService")]
public interface IAttenttoService
{
[OperationContract]
void CreateUser(User user);
}
[DataContract]
public class User
{
[DataMember]
public string Username { get; set; }
[DataMember]
public string Password { get; set; }
[DataMember]
public string Country { get; set; }
[DataMember]
public string Email { get; set; }
}
}
名称空间AttenttoWcfService
{
[ServiceContract(Namespace=“JsonpAjaxService”)]
公共接口IAttenttoService
{
[经营合同]
void CreateUser(用户用户);
}
[数据合同]
公共类用户
{
[数据成员]
公共字符串用户名{get;set;}
[数据成员]
公共字符串密码{get;set;}
[数据成员]
公共字符串国家{get;set;}
[数据成员]
公共字符串电子邮件{get;set;}
}
}
和Web.Config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appSettings />
<connectionStrings />
<system.web>
<compilation debug="true">
<assemblies>
<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.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</assemblies>
</compilation>
<authentication mode="None" />
<!--<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>-->
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"></modules>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
</customHeaders>
</httpProtocol>
</system.webServer>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5" />
<providerOption name="WarnAsError" value="false" />
</compiler>
</compilers>
</system.codedom>
<system.serviceModel>
<services>
<service behaviorConfiguration="ServiceBehavior" name="AttenttoWcfService.AttenttoService">
<endpoint address="basic" binding="webHttpBinding" contract="AttenttoWcfService.IAttenttoService" behaviorConfiguration="EndpBehavior" />
</service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"></serviceHostingEnvironment>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="EndpBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
可能会帮助您。或服务:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appSettings />
<connectionStrings />
<system.web>
<compilation debug="true">
<assemblies>
<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.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</assemblies>
</compilation>
<authentication mode="None" />
<!--<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>-->
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"></modules>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
</customHeaders>
</httpProtocol>
</system.webServer>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5" />
<providerOption name="WarnAsError" value="false" />
</compiler>
</compilers>
</system.codedom>
<system.serviceModel>
<services>
<service behaviorConfiguration="ServiceBehavior" name="AttenttoWcfService.AttenttoService">
<endpoint address="basic" binding="webHttpBinding" contract="AttenttoWcfService.IAttenttoService" behaviorConfiguration="EndpBehavior" />
</service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"></serviceHostingEnvironment>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="EndpBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>