0

C#を使用してデモ用のOPCXMLDAサーバーを構築しようとしています。開発は進行中ですが、アレイに関するシリアル化の問題で立ち往生しています。どうやら、ItemProperty.Value(Object型)をbyte []以外の任意の種類の配列に設定しようとすると、次の例外が発生します。

System.InvalidOperationException:タイプ<ArrayType>はこのコンテキストでは使用できません。

例外をトリガーするサンプルのGetProperties()メソッドの内容は次のとおりです。

[WebMethodAttribute()]
[
    SoapDocumentMethodAttribute
    (
        "http://opcfoundation.org/webservices/XMLDA/1.0/GetProperties", 
        RequestNamespace = "http://opcfoundation.org/webservices/XMLDA/1.0/", 
        ResponseNamespace = "http://opcfoundation.org/webservices/XMLDA/1.0/", 
        Use = SoapBindingUse.Literal, 
        ParameterStyle = SoapParameterStyle.Wrapped
    )
]
public override ReplyBase GetProperties
(
    [XmlElementAttribute("ItemIDs")] ItemIdentifier[] ItemIDs, 
    [XmlElementAttribute("PropertyNames")] XmlQualifiedName[] PropertyNames, 
    [XmlAttributeAttribute()] string LocaleID, 
    [XmlAttributeAttribute()] string ClientRequestHandle, 
    [XmlAttributeAttribute()] string ItemPath, 
    [XmlAttributeAttribute()] [DefaultValueAttribute(false)] bool ReturnAllProperties,
    [XmlAttributeAttribute()] [DefaultValueAttribute(false)] bool ReturnPropertyValues,
    [XmlAttributeAttribute()] [DefaultValueAttribute(false)] bool ReturnErrorText, 
    [XmlElementAttribute("PropertyLists")] out PropertyReplyList[] PropertyLists, 
    [XmlElementAttribute("Errors")] out OPCError[] Errors
)
{
    ReplyBase Response = new ReplyBase();
    Response.RcvTime = System.DateTime.Now;

    Response.RevisedLocaleID = LocaleID;
    Response.ClientRequestHandle = ClientRequestHandle;

    Errors = null;

    PropertyLists = new PropertyReplyList[1] { new PropertyReplyList() };
    PropertyLists[0].Properties = new ItemProperty[1] { new ItemProperty() };
    PropertyLists[0].Properties[0].Value = new short[2] { 3, 4 };

    Response.ReplyTime = System.DateTime.Now;
    return Response;
}

フルスタックトレース(イタリア語)

System.Web.Services.Protocols.SoapException: Impossibile elaborare la richiesta. ---> System.InvalidOperationException: Errore durante la generazione del documento XML. ---> System.InvalidOperationException: Il tipo System.Int16[] può non essere utilizzato in questo contesto.
in System.Xml.Serialization.XmlSerializationWriter.WriteTypedPrimitive(String name, String ns, Object o, Boolean xsiType)
in Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write2_Object(String n, String ns, Object o, Boolean isNullable, Boolean needType)
in Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write16_ItemProperty(String n, String ns, ItemProperty o, Boolean isNullable, Boolean needType)
in Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write19_PropertyReplyList(String n, String ns, PropertyReplyList o, Boolean isNullable, Boolean needType)
in Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write26_GetPropertiesResponse(Object[] p)
in Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer13.Serialize(Object objectToSerialize, XmlSerializationWriter writer)
in System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
--- Fine della traccia dello stack dell'eccezione interna ---
in System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
in System.Web.Services.Protocols.SoapServerProtocol.WriteReturns(Object[] returnValues, Stream outputStream)
in System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[] returnValues)
in System.Web.Services.Protocols.WebServiceHandler.Invoke()
--- Fine della traccia dello stack dell'eccezione interna ---

私はすでにwsdl.exeによって生成されたサービススケルトンをプロジェクトに含めており、配列以外の値についてはまったく問題がありません。私のプロジェクトのターゲットフレームワークは.NET4.0です(ただし、3.5でも同じ問題が発生します)。

私の推測では、このメソッドはサービススケルトンのXmlIncludeAttribute()デコレータではうまく機能していません。それを機能させる方法についての手がかりはありますか?

お時間をいただきありがとうございます。

編集:XmlIncludeAttribute(typeof(int []))デコレータをGetProperties()メソッドに追加しようとしましたが(デコレータは継承できないと思います)、例外は発生しません。ただし、クライアントは基になるデータを適切に逆シリアル化できません。シリアル化解除後にクライアント(VB.NETで記述)から取得するのは、int[]ではなくXmlNode参照です。データはそこにありますが、適切にシリアル化されていません。

これは予想される動作ですか?それはクライアントの問題でしょうか?

4

1 に答える 1

0

生成されたXMLをもう少し分析した結果、データを適切に逆シリアル化するために、クライアントが特定の名前空間(OPC Webサービスのデフォルトの名前空間)を必要としていることがわかりました。次のデコレータを使用して、Webサービス実装のクラス定義を更新しました。

[WebService(Namespace = "http://opcfoundation.org/webservices/XMLDA/1.0/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[XmlInclude(typeof(short[]))]

GetProperties()メソッドが適切に動作するようになり、クライアントはInt16の配列を適切に逆シリアル化できるようになりました。

于 2011-09-08T08:19:37.860 に答える