【发布时间】:2013-12-19 03:49:03
【问题描述】:
创建了 Wcf Restful 服务并托管在本地服务器中。另一个用户正在尝试通过 ajax 调用从 HTML5 页面使用 WCF Rest 服务。但是总是抛出失败消息
配置设置:
1.WCF Rest Service 托管在http://jtl_109.com/mob/AppService.svc/GetUserAuthendication 2.创建一个 HTML5 应用程序并将其部署在另一台服务器上。网址是http://jtl_110.com/SampleApplication.html
WCF 托管配置设置:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
</customHeaders>
</httpProtocol>
</system.webServer>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
<add key="ConnectionString" value="Data Source=ServerDatabase; Initial Catalog=NewDataBase; User ID=pras; Password=rita" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<authentication mode="Windows" />
<roleManager enabled="true" />
</system.web>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="crossDomain" crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="tSeyvaWCFEndPointBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="tSeyvaServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="AppServices.AppService" behaviorConfiguration="tSeyvaServiceBehavior">
<endpoint address="" behaviorConfiguration="tSeyvaWCFEndPointBehavior"
bindingConfiguration="crossDomain" binding="webHttpBinding"
contract="AppServices.IAppService">
</endpoint>
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true" />
<handlers accessPolicy="Read, Execute, Script" />
</system.webServer>
</configuration>
而ajax调用是
var data = { 'logindetails': { 'UserName': UN, 'Password': PW } };
var st = JSON.stringify(data);
debugger;
$.ajax({
type: "POST",
url: "http://jtl_109/mob/AppService.svc/GetUserAuthendication",
data: st,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
ServiceSucceeded(result);
//// Play with response returned in JSON format
},
error: function (jqXHR, textStatus, errorThrown) {
alert(jqXHR + "-" + textStatus + "-" + errorThrown);
}
});
谁能建议如何从另一个站点使用 WCF 重置服务?
【问题讨论】:
-
你的“服务器”在哪里?远程服务器?
-
是的,它是一个远程服务器。
-
我的审讯导致了@Brian 所说的。检查下面。
-
我试过了,我得到页面无法显示错误
-
你有什么别的想法吗...???