2009-11-13 76 views
2

我正在尝试为WSE3/ASMX Web服务编写WCF包装Web服务。 [丑陋的原因是,第三方供应商不支持SSL,而这正是BizTalk 2009 WCF适配器与WS-Security一起使用所需的。因此,如果供应商不改变 - 我需要调用本地WCF web服务...]'Microsoft.Web.Services3.Addressing.Address'无法序列化

我跟着这篇文章来获得WSE3代理生成器内置到VS2008: http://blogs.imeta.co.uk/jyoung/archive/2008/08/29/345.aspx 我做一个网页参考供应商的.asmx远程Web服务。

,制作并在本地发布我的web服务,只是尽量把它在浏览器中,并得到这个错误:

System.InvalidOperationException: An exception was thrown in a call to a WSDL export extension: System.ServiceModel.Description.DataContractSerializerOperationBehavior contract: http://tempuri.org/:IValuationService ----> System.Runtime.Serialization.InvalidDataContractException: Type 'Microsoft.Web.Services3.Addressing.Address' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. See the Microsoft .NET Framework documentation for other supported types.

我怎样才能让一个对象,我没有写(“微软.Web.Services3.Addressing.Address')可序列化?是否有可能完成我所尝试的?

感谢,

尼尔·沃尔特斯


附加信息 - 星期一2009年11月16日:


[ServiceContract] 
public interface IValuationService 
{ 
    [OperationContract] 
    ExpressLync.ValuationServiceWse GetPropertyInfoSourceRecordPolicyNum(string PolicyNumber); 
} 
// end of interface 

// here is part of reference.cs... 
public partial class ValuationServiceWse : Microsoft.Web.Services3.WebServicesClientProtocol { 
... 

我能找到的任何参考什么那么以往任何时候都只有一个地方到'Microsoft.Web.Services3.Addressing.Address' 在这里,当我做一个“定义”Microso的元数据ft.Web.Services3.WebServicesClientProtocol

using Microsoft.Web.Services3.Addressing; 
using Microsoft.Web.Services3.Design; 
using System; 
using System.Net; 
using System.Web.Services.Protocols; 
using System.Xml; 

namespace Microsoft.Web.Services3 
{ 
    public class WebServicesClientProtocol : SoapHttpClientProtocol 
    { 
     public WebServicesClientProtocol(); 

     public EndpointReference Destination { get; set; } 
     public Pipeline Pipeline { get; set; } 
     public SoapContext RequestSoapContext { get; } 
     public bool RequireMtom { get; set; } 
     public SoapContext ResponseSoapContext { get; } 
     public string Url { get; set; } 
     public bool UseDefaultCredentials { get; set; } 

     public TSecurityToken GetClientCredential<TSecurityToken>() where TSecurityToken : Microsoft.Web.Services3.Security.Tokens.SecurityToken; 
     protected override XmlReader GetReaderForMessage(SoapClientMessage message, int bufferSize); 
     public TSecurityToken GetServiceCredential<TSecurityToken>() where TSecurityToken : Microsoft.Web.Services3.Security.Tokens.SecurityToken; 
     protected override WebRequest GetWebRequest(Uri uri); 
     protected override WebResponse GetWebResponse(WebRequest request); 
     protected override WebResponse GetWebResponse(WebRequest request, IAsyncResult result); 
     protected override XmlWriter GetWriterForMessage(SoapClientMessage message, int bufferSize); 
     public void SetClientCredential<TSecurityToken>(TSecurityToken clientToken) where TSecurityToken : Microsoft.Web.Services3.Security.Tokens.SecurityToken; 
     public void SetPolicy(Policy policy); 
     public void SetPolicy(string policyName); 
     public void SetServiceCredential<TSecurityToken>(TSecurityToken serviceToken) where TSecurityToken : Microsoft.Web.Services3.Security.Tokens.SecurityToken; 
    } 
} 

因此,换句话说,我该如何摆脱 'Microsoft.Web.Services3.Addressing.Address' 的? 似乎EndpointReference位于'Microsoft.Web.Services3.Addressing.Address'对象中。所以如果我使用WSE3生成的代码,它会尝试序列化它。

所以我认为解决方案将是写另一个WSE3免费包装 - 并通过WCF公开它。但诀窍是供应商Web服务有许多大而复杂的对象 - 现在它们都从Microsoft.Web.Services3.WebServicesClientProtocol继承(因为我使用的是WS3代码生成器)。我真的不想再次手动构建它们。在上面的例子中,“ValuationService”就是这样的对象之一。

回答

1

好的,这是问题所在。我变得有点混浊,并且在这个应用程序的复杂性中丢失了一些东西,它暴露了4种服务和几十种方法,并且第一次使用WCF的WSE3。

错误是因为我写的包装器试图返回ValuationService本身。那是一个愚蠢的错误。 ValuationService确实实现了Microsoft.Web.WebServices3.WebServicesClientProtocol,其中包含导致该问题的Addressing类。

包装应该使用ValuationService作为客户端,并且只返回Valuation(或ValuationResult)。 valuationResult当然只是一个由字符串,小数点,布尔值等组成的对象......可以被序列化。

1

“事后”无法制作可串行化的东西。问题是:你需要什么“地址”?

你可能会改变你的WCF包装,这样你就可以从你的客户端向你的WCF服务传递一个地址(如果这是我怀疑的URL),然后在里面创建一个“Address”的实例你的WCF服务类?

+0

如何摆脱“Microsoft.Web.Services3.Addressing.Address”?这似乎是“插入本身,这是我想具体包括的任何东西。 – NealWalters 2009-11-16 14:29:28

+0

解决 - 看到我的答案如下。 – NealWalters 2009-11-16 15:44:44

+0

好吧,很高兴你能解决它! – 2009-11-16 19:56:00