简体   繁体   English

在两个WCF服务之间共享类库

[英]Sharing a class library between two WCF services

I have two WCF service applications which pass Data Transfer Objects between each other to perform certain actions. 我有两个WCF服务应用程序,它们相互之间传递数据传输对象以执行某些操作。 I have moved the DataContracts to a Common project as this seems like the logical thing to do, but I am having problems adding a service reference to one of the WCF service applications. 我已将DataContracts移动到Common项目,因为这似乎是合乎逻辑的事情,但我在向其中一个WCF服务应用程序添加服务引用时遇到问题。 I'm getting 4 similar errors for different parts of the service (contract, service etc): 我为服务的不同部分(合同,服务等)收到4个类似的错误:

Custom tool warning: Cannot import wsdl:portType Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter Error: Referenced type 'ServiceLibraryName.Common.Data.LicenceForm, Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' with data contract name 'LicenceForm' in namespace 'http://schemas.datacontract.org/2004/07/ServiceLibraryName.Common.Data' cannot be used since it does not match imported DataContract. 自定义工具警告:无法导入wsdl:portType详细信息:运行WSDL导入扩展时抛出了异常:System.ServiceModel.Description.DataContractSerializerMessageContractImporter错误:引用类型'ServiceLibraryName.Common.Data.LicenceForm,通用,版本= 1.0.0.0,无法使用名称空间“http://schemas.datacontract.org/2004/07/ServiceLibraryName.Common.Data”中的数据合同名称“LicenceForm”的Culture = neutral,PublicKeyToken = null',因为它与导入的DataContract不匹配。 Need to exclude this type from referenced types. 需要从引用的类型中排除此类型。 XPath to Error Source: //wsdl:definitions[@targetNamespace='http://schemas.datacontract.org/2004/07/ServiceLibraryName.Common.Data']/wsdl:portType[@name='ILicenceGeneration'] C:\\SourceCode\\Release 2 \\ServiceLibraryName\\Sharepoint\\Service References\\LicenceGenerationCrm\\Reference.svcmap 1 1 Sharepoint 错误的XPath来源://wsdl:definitions[@targetNamespace='http://schemas.datacontract.org/2004/07/ServiceLibraryName.Common.Data']/wsdl:portType[@name='ILicenceGeneration'] C: \\ SourceCode \\ Release 2 \\ ServiceLibraryName \\ Sharepoint \\ Service References \\ LicenceGenerationCrm \\ Reference.svcmap 1 1 Sharepoint

I am certain that the referenced file assembly is the same file on both service and consumer, but I can do nothing to get rid of this message. 我确定引用的文件程序集在服务和使用者上都是相同的文件,但是我无法采取任何措施来消除此消息。 Reuse assemblies in the Service Reference Configuration is checked. 将检查“服务引用配置”中的重用程序集。

Using SVCUtil and referencing the assembly also produces the same error. 使用SVCUtil并引用程序集也会产生相同的错误。

Any ideas or suggestions would be welcome. 任何想法或建议都将受到欢迎。

The WCF WSDL generator defaults to using a portion of the C# namespaces of the service classes to generate the XML namespaces referenced in the WSDL. WCF WSDL生成器默认使用服务类的一部分C#名称空间来生成WSDL中引用的XML名称空间 Since you have two services using a common project (that has its own C# namespace), the WSDL generated is likely different for the "common" DataContract classes. 由于您有两个使用公共项目(具有自己的C#名称空间)的服务,因此生成的WSDL可能与“常见”DataContract类不同。

You can control the XML namespace for the DataContract marked classes (and also the OperationContract & ServiceContract attributes) by using the Namespace property . 您可以使用Namespace属性来控制DataContract标记类的XML名称空间(以及OperationContract和ServiceContract属性)。 This can be really tedious if you have a lot of DTOs so as an alternative, set the assembly level ContractNamespace attribute to mark all appropriate classes. 如果您有很多DTO,这可能非常繁琐,因此,可以选择设置程序集级别ContractNamespace属性以标记所有适当的类。

Turns out that this was a problem caused by a piece of code which I added to handle Cdata fields as strings. 事实证明这是一个问题引起的问题,我添加了一些代码来处理Cdata字段作为字符串。 When I changed this field to a string rather than the CdataWrapper it worked correctly. 当我将此字段更改为字符串而不是CdataWrapper时,它正常工作。

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

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