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

问题描述 投票:10回答:2

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

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

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

[[IOException:读取操作失败,请参阅内部异常。]System.Net.Security.NegotiateStream.ProcessRead(字节[]缓冲区,Int32偏移量,Int32计数,AsyncProtocolRequest asyncRequest)+704System.Net.Security.NegotiateStream.Read(字节[]缓冲区,Int32偏移量,Int32计数)+154System.ServiceModel.Channels.StreamConnection.Read(Byte []缓冲区,Int32偏移量,Int32大小,TimeSpan超时)+87

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

这让我开始思考:SharePoint做到了,并且他们以一种不错的方式来做到这一点,因为它们在14\WebClients中具有单独的服务配置。

我反映并克隆了很多(ChannelFactory的扩展方法在内部各处使用-SPChannelFactoryOperations,但我想知道:SharePoint用于调用其自身WCF服务的“适当” API是否公开了?外部代码,以便可以从自定义SharePoint代码调用非SharePoint WCF服务?

((这是部署到GAC的服务器场解决方案,因此CAS和Sandboxing均不适用)

c# .net sharepoint sharepoint-2010
2个回答
2
投票

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


0
投票

我建议尝试忽略证书。

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

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

© www.soinside.com 2019 - 2024. All rights reserved.