实现外部 WSDL 获取的接口

Implementing external WSDL-obtained interface

(呃,这很有可能是有意义的。我可能没有足够的知识来进行智能搜索...)

因此,这里的想法是向我提供一个 WSDL 文件,我成功地将其导入 Visual Studio 作为服务参考。我可以看到它生成的界面很好。

我在自己的项目中创建了一个 Web 服务。在那里,在 IMyService 中,我公开了我需要的方法,在 MyService.cs 中,我同时实现了 IMyService 和 IWSDLInterface。

逻辑如下:

[ServiceContract(Namespace = Constants.Namespace)]
public interface IMyService
{
/// <summary>
/// A simple WebGet that runs a test.
/// </summary>
[WebGet(UriTemplate = "Test")]
[OperationContract]
void Test();

[OperationContract]
CustomObject1 IWSDLInterfaceMethod1(CustomObjectReturn1 firstOperation);

[OperationContract]
CustomObject2 IWSDLInterfaceMethod2(CustomObjectReturn2 secondOperation);

}

这是我公开的服务。这是我获得的外部接口:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://eventmanager.xmlns.oracle.com/", 
ConfigurationName="ImportedWSDL.InterfaceIWantToImplement")]
public interface InterfaceIWantToImplement{

    // Example for IWSDLInterfaceMethod1; there are more things to implement here.

    [System.ServiceModel.OperationContractAttribute(Action="IWSDLInterfaceMethod1", ReplyAction="*")]
    [System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
    ImportedWSDL.customObject1 IWSDLInterfaceMethod1(ImportedWSDL.customObjectReturn1 firstOperation);


}

在 MyService.cs 中实现该接口工作正常。问题是,当通过 SOAP 调用 MyService 时,我总是遇到以下异常:

The formatter threw an exception while trying to deserialize the message: 
There was an error while trying to deserialize parameter 
[customObjectReturn1.firstParameter]. //changed name to make sense with the above code 
The InnerException message was 'The constructor with parameters 
(SerializationInfo, StreamingContext) is not found in ISerializable 
type 'System.Delegate'.'.  Please see InnerException for more details.

如果我没有理解错的话,此消息表明对我的服务的 SOAP 调用因无法反序列化 customObjectReturn1 的第一个参数而失败。然而,这对我来说意义不大——我可以浏览我的 WSDL,我会看到所有描述的对象;将 WSDL 导入 SoapUI 确实 识别预期的参数及其属性,因此它们显然存在。

Constructor not found during deserialization? 这有一些关于修复的信息,但由于我不直接控制 类(它们在 ImportedWSDL 的自动生成代码上),所以不会有太大帮助对我来说编辑自动生成的代码很有意义。

所以,

在此先感谢您。

来自上面的评论:

System.Delegate是一个抽象class,虽然有Seri​​alizationAttribute,但是没有实现。你不能 serialize/deserialize System.Delegate。派生的 class 必须实现反序列化调用的特殊构造函数。在你的情况下,它似乎没有。这将由您尝试使用的 Web 服务的开发人员来解决。