简体   繁体   English

WCF客户端计算机是否必须需要WCF服务已引用的所有DLL?

[英]Do WCF Client machine MUST needs to have all DLLs WCF service has referenced to?

Edit 编辑

Please add a reference to your answer, so I could convince my system admin. 请添加对您的答案的引用,以便我说服我的系统管理员。 Thanks 谢谢

Scenario 脚本

I have a WCF web services, which has reference to few third party dlls, eg Microsoft.SharePoint, now when I try to call web services from client machine using this code, it says Microsoft.SharePoint not found. 我有一个WCF Web服务,它引用了一些第三方dll,例如Microsoft.SharePoint,现在当我尝试使用此代码从客户端计算机调用Web服务时,它表示未找到Microsoft.SharePoint。

Problem does goes away when I add Microsoft.SharePoint to client machine's GAC, but I am failed to explain it to our System Admin as why we need to add Microsoft.SharePoint dll to client WCF machine. 当我将Microsoft.SharePoint添加到客户端计算机的GAC时,问题确实消失了,但是由于我们为什么需要将Microsoft.SharePoint dll添加到客户端WCF计算机,我无法向我们的系统管理员解释它。 Can someone explain why we must need to add WCF service's referenced dlls to client machine.. 有人可以解释为什么我们必须将WCF服务的引用的dll添加到客户端计算机。

BTW, I deployed WCF service by making Microsoft.SharePoint copy local but not much changes. 顺便说一句,我通过将Microsoft.SharePoint复制到本地但没有太多更改来部署了WCF服务。

Here is the error, I get when I remove dll from GAC, 这是错误,当我从GAC删除dll时出现错误,

Description: Could not load file or assembly 'Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. 说明:无法加载文件或程序集“ Microsoft.SharePoint,版本= 15.0.0.0,文化=中性,PublicKeyToken = 71e9bce111e9429c”或其依赖项之一。 The system cannot find the file specified. 该系统找不到指定的文件。

Server stack trace: at SourceCode.Workflow.Runtime.Extenders.CodeExtender.OnExecute(Object context, XmlElement data, ResolverManager resolverManager) at SourceCode.Workflow.Runtime.Extenders.ResolverExtenderBase.Execute(Object context, String data) at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs) at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg) 服务器堆栈跟踪:位于System.Runtime的SourceCode.Workflow.Runtime.Extenders.ResolverExtenderBase.Execute(对象上下文,字符串数据)处,位于SourceCode.Workflow.Runtime.Extenders.CodeExtender.OnExecute(对象上下文,XmlElement数据,ResolverManager resolverManager)处。 Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md,Object [] args,对象服务器,Object []&outArgs)在System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)

Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at SourceCode.Workflow.Runtime.IK2Extender.Execute(Object context, String data) at SourceCode.KO.ProcessInstance.ExecuteExtender(Guid , State , ContextType , Object , Int32 , String , Guid )An exception was thrown during execution of a K2 workflow. 异常在[0]处重新抛出:在System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&msgData,Int32类型)的System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,IMessage retMsg)处。 SourceCode.KO.ProcessInstance.ExecuteExtender(Guid,State,ContextType,Object,Int32,String,Guid)上的Runtime.IK2Extender.Execute(对象上下文,字符串数据)在执行K2工作流期间引发了异常。 This process instance is now in an error state. 现在,该流程实例处于错误状态。 The details of the exception are listed below. 下面列出了例外的详细信息。

Code

System.Net.NetworkCredential creds = GetNetWorkCredentials();
   BasicHttpBinding binding = new BasicHttpBinding();
   binding.Security.Mode = BasicHttpSecurityMode.Transport;
   binding.Security.Transport.ClientCredentialType = creds.httpClientCredentialType;
   ChannelFactory<Portal.WebServices.Internal.IPort> factory = new ChannelFactory<Portal.WebServices.Internal.IPort>(binding);
   factory.Credentials.Windows.ClientCredential = creds;
   factory.Credentials.UserName.UserName = creds.UserName;
   factory.Credentials.UserName.Password = creds.Password;
   Portal.WebServices.Internal.IPort proxy = factory.CreateChannel(new EndpointAddress(siteURL + "/_vti_bin/portal/Port.svc"));
   Portal.WebServices.Internal.FewObject[] invoices = proxy.GetInvoices(IDs);

You don't need to add Dlls you add to a WCF service to a client server, but only when you add an object to it's interface. 您无需将添加到WCF服务的Dll添加到客户端服务器,而仅在将对象添加到其接口时才添加。

One of workmate added an OperationContract as below, 一个同事添加了一个OperationContract,如下所示,

[OperationContract]
    void AddEventReceiver(string siteUrl, string listName, string assemblyName, string className, SPEventReceiverType receiverType);

WCF service was failing because it couldn't compile referenced object in the interface, in my case "SPEventReceiverType". WCF服务失败,因为它无法编译接口中的引用对象,在本例中为“ SPEventReceiverType”。

So make sure you add object references to client machines if they are not generic types. 因此,如果不是通用类型,请确保将对象引用添加到客户端计算机。

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

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