繁体   English   中英

如何从 SharePoint 2010 正确调用外部 WCF 服务?

[英]How to properly call an external WCF Service from SharePoint 2010?

我想从 SharePoint 中调用外部 WCF 服务。 使用正常的 WCF 调用会立即导致SocketException (现有连接被远程主机强制关闭),可以使用SPSecurity.RunWithElevatePrivileges规避。

[SocketException (0x2746): 现有连接被远程主机强行关闭]
System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) +85
System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] 缓冲区,Int32 偏移量,Int32 大小,TimeSpan 超时,Boolean 关闭)+204

[CommunicationException:套接字连接被中止。 这可能是由于处理您的消息时出错或远程主机超出接收超时,或者是潜在的网络资源问题造成的。 本地套接字超时为 '00:00:58.7210000'。]
System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] 缓冲区,Int32 偏移量,Int32 大小,TimeSpan 超时,Boolean 关闭)+15307563
System.ServiceModel.Channels.SocketConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout) +90
System.ServiceModel.Channels.DelegatingConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout) +34
System.ServiceModel.Channels.ConnectionStream.Read(Byte[] buffer, Int32 offset, Int32 count, TimeSpan timeout) +34
System.ServiceModel.Channels.ConnectionStream.Read(Byte[] buffer, Int32 offset, Int32 count) +88
System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count) +58
System.Net.Security.NegotiateStream.StartFrameHeader(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest) +62
System.Net.Security.NegotiateStream.StartReading(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest) +54
System.Net.Security.NegotiateStream.ProcessRead(Byte[] 缓冲区,Int32 偏移量,Int32 计数,AsyncProtocolRequest asyncRequest) +402

[IOException:读取操作失败,请参阅内部异常。]
System.Net.Security.NegotiateStream.ProcessRead(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest) +704
System.Net.Security.NegotiateStream.Read(Byte[] buffer, Int32 offset, Int32 count) +154
System.ServiceModel.Channels.StreamConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout) +87

[CommunicationException:套接字连接被中止。 这可能是由于处理您的消息时出错或远程主机超出接收超时,或者是潜在的网络资源问题造成的。 本地套接字超时为 '00:00:58.7210000'。]
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +10257978
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 类型) +539
MyApp.FunctionThatCallsService()

这让我想到: SharePoint 做到了,而且他们做得很好,他们在14\WebClients中有单独的服务配置。

我反映并克隆了很多(ChannelFactory 上的扩展方法在内部到处都在使用 - SPChannelFactoryOperations ),但我想知道:SharePoint 用来调用它自己的 WCF 服务的“正确”API 是否暴露给外部代码,以便我可以从自定义 SharePoint 代码调用我的非 SharePoint WCF 服务?

(这是部署到 GAC 的场解决方案,因此 CAS 和沙盒都不适用)

最终保留了SPSecurity.RunWithElevatedPrivileges部分。 Microsoft 的SPChannelFactoryOperations在某些时候遇到 NullReferenceException,很可能是由于即使不使用它也需要在服务中设置声明( SPServiceAuthenticationMode只有SPServiceAuthenticationMode.Claims作为成员CreateChannelActingAsLoggedOnUser()立即抛出 ArgumentException 的事实是一个信号SPChannelFactoryOperations不打算由非 Microsoft 代码使用。

我建议尝试忽略证书。

http://www.fryan0911.com/2006/07/vbnet-how-to-accept-web-service-ssl.html

也许您需要代理? 您是否遇到某种类型的端口阻塞问题?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM