如何从javascript客户端调用安全的WCF Rest服务?
这应该很容易,但我无法找到解决办法。 是否可以从javascript客户端调用安全的wcf服务? 我正在运行安全的WCF Rest服务。我已使用makecert.exe将.X509证书添加到iy。我已在IIS上托管了我的服务,并已将证书添加到我的服务中 我有一个javascript客户端来调用服务。现在,当我点击该服务时,我得到了eror:https:/192.168.0.5/Rest/net::ERR\u unsecure\u响应 如何使我的javascript客户端访问该服务?? 这是我的服务的web.config:如何从javascript客户端调用安全的WCF Rest服务?,javascript,jquery,web-services,wcf,rest,Javascript,Jquery,Web Services,Wcf,Rest,这应该很容易,但我无法找到解决办法。 是否可以从javascript客户端调用安全的wcf服务? 我正在运行安全的WCF Rest服务。我已使用makecert.exe将.X509证书添加到iy。我已在IIS上托管了我的服务,并已将证书添加到我的服务中 我有一个javascript客户端来调用服务。现在,当我点击该服务时,我得到了eror:https:/192.168.0.5/Rest/net::ERR\u unsecure\u响应 如何使我的javascript客户端访问该服务?? 这是我的服
<system.serviceModel>
<services>
<service name="RestDemo.RestDemo" behaviorConfiguration="serviceBehavior">
<host>
<baseAddresses>
<add baseAddress="https://localhost/RestDemo/RestDemo.svc" />
</baseAddresses>
</host>
<endpoint address="" binding="webHttpBinding" contract="RestDemo.IRestDemo" behaviorConfiguration="web">
<!--<identity>
<dns value="localhost"/>
</identity>-->
</endpoint>
<endpoint address="mex" binding="mexHttpsBinding" contract="RestDemo.IRestDemo" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="web">
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceCredentials>
<clientCertificate>
<authentication certificateValidationMode="PeerTrust"
trustedStoreLocation="LocalMachine" />
</clientCertificate>
<serviceCertificate findValue="ServerCertificate"
storeLocation="LocalMachine"
storeName="My"
x509FindType="FindBySubjectName" />
</serviceCredentials>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" httpsGetUrl="/RestDemo.svc" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
**Here is my javascript client:**
<script type="text/javascript">
$(document).ready(function () {
$('#btnCall').click(function () {
debugger;
var name = "test";
$.ajax({
type: "GET",
// url: "http://localhost:49620/RestDemo.svc/DoWork/"+name,
url: "https://192.168.0.15/Rest/",
dataType: "xml",
success: function (xml) {
alert("success");
var xmlText = new XMLSerializer().serializeToString(xml);
alert(xmlText);
},
error: function (xhr) {
alert(xhr.responseText);
alert("error");
}
});
});
});
</script>
**这是我的javascript客户端:**
$(文档).ready(函数(){
$('#btnCall')。单击(函数(){
调试器;
var name=“测试”;
$.ajax({
键入:“获取”,
//url:“http://localhost:49620/RestDemo.svc/DoWork/“+姓名,
url:“https://192.168.0.15/Rest/",
数据类型:“xml”,
成功:函数(xml){
警惕(“成功”);
var xmlText=new XMLSerializer().serializeToString(xml);
警报(xmlText);
},
错误:函数(xhr){
警报(xhr.responseText);
警报(“错误”);
}
});
});
});
任何建议都将不胜感激。您运行javascript的浏览器是否信任您的自签名证书?您是否在
IIS
中为该服务正确激活了SSL
?@stuartd:我可以从IIS浏览到服务。.服务刚刚打开fine@Mirjalal塔利辛斯基:是的,因为我能够添加已成功向IIS上承载的服务颁发证书。。。我可以从IISI浏览到该服务,我已经找到了一些解决此问题的选项:1)删除httpsGetUrl=“/RestDemo.svc”
2)将httpGetEnabled=“false”
更改为httpGetEnabled=“true”
3)在您编写的ajax调用中url:“https://192.168.0.15/Rest/“
。将其更改为url:“https://192.168.0.15/YourServiceName.svc/yourMethodName“
p.s我知道这些1)
和2)
看起来很愚蠢。但是为了解决这个问题,你应该尝试这些方法。希望对你有所帮助。