【问题标题】:Authenticating to Custom WCF Service in Sharepoint 2010在 Sharepoint 2010 中对自定义 WCF 服务进行身份验证
【发布时间】:2012-06-07 18:47:49
【问题描述】:

我在 SharePoint 2010 中创建了一个自定义 WCF 服务,我试图通过 JQuery Ajax 请求调用该服务。我的自定义 WCF 服务以此处给出的示例为模型:

链接:http://blog.sharepointbits.com/2010/04/custom-wcf-services-in-sharepoint-2010_17.html

上述方法为我提供了一个可以从 C# 服务器端代码访问的 WCF 服务和一个自定义 InfoPath 表单,但是,我无法使用 JQuery Ajax 获得响应。

我在 Stack Overflow 上的其他地方阅读到使用 MultipleBaseAddressWebServiceHostFactory 而不是原始文章建议的 MultipleBaseAddressBasicHttpBindingServiceHostFactory。

链接:Sharepoint 2010 wcf service. call method with jquery

这很有效,但允许我通过 JQuery Ajax 联系(但不验证)服务,

a) 我无法再导航到 http://[servername]/_vti_bin/Service.svc/mex 并查看 WSDL。这个问题意味着我的 InfoPath 表单也无法连接到该服务,因为它们会查找 WSDL。

b) 即使 JQuery Ajax 请求命中自定义 WCF 服务,浏览器每次都要求我进行身份验证,即使该请求来自登录到 SharePoint 的用户的浏览器。

如果有人知道如何解决 a) 和 b) 的问题,我将不胜感激。制作可以在任何应用程序中使用的服务真的应该不难。

【问题讨论】:

  • 如果您找到解决方案,请在此处提供答案。我有兴趣。

标签: jquery wcf authentication sharepoint-2010 active-directory


【解决方案1】:

经过一番折腾,我坚持使用MultipleBaseAddressBasicHttpBindingServiceHostFactory。我没有尝试通过 JSON 联系 WCF 服务,而是创建了一个函数来创建 SOAP 消息,将其发送到 WCF 服务,然后解析结果。

有趣的是,这似乎也解决了我的身份验证问题,尽管我不清楚为什么。

现在可以从 InfoPath 和 JavaScript 使用该服务。

作为参考,从 JavaScript 到 WCF 的 SOAP 消息应如下所示:

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">                
    <soap:Body>
       <MethodName xmlns="http://tempuri.org/"> 
           <ParamName1>Value</ParamName1>
           <ParamName2>Value</ParamName2>
       </MethodName> 
    </soap:Body> 
 </soap:Envelope>

以及发送它的 JQuery:

$.ajax({
    type: "POST",
    url: url,
    data: soapEnvelope,
    timeout: timeOut,
    contentType: "text/xml",
    dataType: "xml",
    beforeSend: function (xhr) {
        xhr.setRequestHeader("SOAPAction", 'http://tempuri.org/' + methodPath);
    },
    success: onSuccess,
    error: onFailure
});

注意:找出 methodPath 的值的最简单方法是查看服务的 WSDL。

【讨论】:

  • 您好,我也有同样的问题,能否请您添加一些有关如何创建肥皂消息以及如何获取“MethodPath”的详细信息??
  • 正如我在答案中所说,查看您的 WCF 服务的 WSDL。在&lt;wsdl:operation&gt; 元素下找到您要调用的方法。 `' 元素的soapAction 属性是完整的方法路径(包括 tempuri 部分)。至于创建 SOAP,我给出了一个完整的例子来说明它需要是什么样子。
猜你喜欢
  • 2011-06-24
  • 2011-08-29
  • 2012-07-28
  • 1970-01-01
  • 1970-01-01
  • 2011-08-26
  • 2019-12-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多