.NET WCF 服务的类型序列化问题:服务 WSDL 在 XSD 中定义空类型 [英] Problems serializing types for a .NET WCF Service: Service WSDL defines empty types in XSD

查看:20
本文介绍了.NET WCF 服务的类型序列化问题:服务 WSDL 在 XSD 中定义空类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 WCF 编写 Web 服务.

  1. 我创建了数据合同.

  2. 我创建了我的服务合同(界面).我定义了方法(其参数的类型与数据协定相同).

  3. 我实现了创建服务类的服务合同.

  4. 我使用 svc 文件和 IIS 托管了我的服务.

  5. 我尝试了我的服务,寻找了 http://localhost/myvirtdiriis/myservice.svc --> 服务已加载,并显示了一个描述我的服务存在的漂亮网页.

  6. 我想看看 WSDL.使用提供的链接,我可以看到仅定义了类型,我只能看到类型定义(如 ),但里面没有任何内容(类型为空).

    立>
  7. 我编写了一个简单的客户端,对操作的调用很顺利,但是当返回类型时它是空的(内部字段具有构造值,而我的服务在那里放置了一些值),例如,调用操作返回由操作契约方法设置的三个字符串类型为Hello"、Hello2"和Hello3"的操作,返回将这些字符串设置为""的类型(构造值,如如果没有发生任何变化).

发生了什么?

好像序列化失败了.

我提供了一些:

A1) 服务合同的一部分:

[ServiceContract(Namespace = "http://opcfoundation.org/webservices/XMLDA/1.0/")]公共接口 IOCXSService {[OperationContract(Action = "http://opcfoundation.org/webservices/XMLDA/1.0/Browse")]BrowseResponse 浏览(BrowseRequest 请求);...}

A2) 服务实现:

公共类 MyService : IOCXSService {...公共浏览响应浏览(浏览请求请求){...}...}

B) 类型:

[DataContract(Namespace = "http://opcfoundation.org/webservices/XMLDA/1.0/", Name = "BrowseResponse")][System.ServiceModel.MessageContractAttribute(WrapperName = "BrowseResponse", WrapperNamespace = "http://opcfoundation.org/webservices/XMLDA/1.0/", IsWrapped = true)]公共类浏览响应{[DataMember(Name = "BrowseResult", Order = 0)]public OCXS.OCXSServiceLibrary.OPCXMLDA10.ReplyBase BrowseResult;[DataMember(Name = "Elements", Order = 1)]公共浏览元素[] 元素;[DataMember(Name = "Errors", Order = 2)]公共 OPCError[] 错误;[DataMember(Name = "ContinuationPoint", Order = 3)]公共字符串 ContinuationPoint;[DataMember(Name = "MoreElements", Order = 4)]公共布尔更多元素;公共浏览响应(){}公共浏览响应(OCXS.OCXSServiceLibrary.OPCXMLDA10.ReplyBase BrowseResult,BrowseElement[] 元素,OPCError[] 错误,字符串 ContinuationPoint,bool MoreElements){this.BrowseResult = BrowseResult;this.Elements = 元素;this.Errors = 错误;this.ContinuationPoint = ContinuationPoint;this.MoreElements = MoreElements;}[DataContract(Namespace = "http://opcfoundation.org/webservices/XMLDA/1.0/", Name = "ReplyBase")]公共类 ReplyBase : System.ComponentModel.INotifyPropertyChanged {私有 System.DateTime rcvTimeField;私有 System.DateTime 回复时间字段;私有字符串 clientRequestHandleField;私有字符串修订的LocaleIDField;私有 serverState serverStateField;[DataMember(Name = "RcvTime", Order = 0)]公共 System.DateTime RcvTime {得到 {返回 this.rcvTimeField;}放 {this.rcvTimeField = 值;this.RaisePropertyChanged("RcvTime");}}[DataMember(Name = "ReplyTime", Order = 1)]公共 System.DateTime 回复时间 {得到 {返回 this.replyTimeField;}放 {this.replyTimeField = 值;this.RaisePropertyChanged("ReplyTime");}}[DataMember(Name = "ClientRequestHandle", Order = 2)]公共字符串 ClientRequestHandle {得到 {返回 this.clientRequestHandleField;}放 {this.clientRequestHandleField = 值;this.RaisePropertyChanged("ClientRequestHandle");}}[DataMember(Name = "RevisedLocaleID", Order = 3)]公共字符串修订的LocaleID {得到 {返回 this.revisedLocaleIDField;}放 {this.revisedLocaleIDField = value;this.RaisePropertyChanged("RevisedLocaleID");}}[DataMember(Name = "ServerState", Order = 4)]公共服务器状态服务器状态{得到 {返回 this.serverStateField;}放 {this.serverStateField = 值;this.RaisePropertyChanged("ServerState");}}公共事件 System.ComponentModel.PropertyChangedEventHandler PropertyChanged;protected void RaisePropertyChanged(string propertyName) {System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;if ((propertyChanged != null)) {propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));}}}[DataContract(Namespace = "http://opcfoundation.org/webservices/XMLDA/1.0/", Name = "BrowseElement")]公共类浏览元素:INotifyPropertyChanged {私有 ItemProperty[] 属性字段;私有字符串名称字段;私有字符串 itemPathField;私有字符串 itemNameField;私人 bool isItemField;private bool hasChildrenField;[DataMember(Name = "Properties", Order = 0)]公共 ItemProperty[] 属性 {得到 {返回 this.propertiesField;}放 {this.propertiesField = 值;this.RaisePropertyChanged("属性");}}[DataMember(Name = "Name", Order = 1)]公共字符串名称{得到 {返回 this.nameField;}放 {this.nameField = 值;this.RaisePropertyChanged("名称");}}[DataMember(Name = "ItemPath", Order = 2)]公共字符串项目路径{得到 {返回 this.itemPathField;}放 {this.itemPathField = 值;this.RaisePropertyChanged("ItemPath");}}[DataMember(Name = "ItemName", Order = 3)]公共字符串项目名称{得到 {返回 this.itemNameField;}放 {this.itemNameField = 值;this.RaisePropertyChanged("ItemName");}}[DataMember(Name = "IsItem", Order = 4)]public bool IsItem {得到 {返回 this.isItemField;}放 {this.isItemField = 值;this.RaisePropertyChanged("IsItem");}}[DataMember(Name = "HasChildren", Order = 5)]public bool HasChildren {得到 {返回 this.hasChildrenField;}放 {this.hasChildrenField = 值;this.RaisePropertyChanged("HasChildren");}}公共事件 System.ComponentModel.PropertyChangedEventHandler PropertyChanged;protected void RaisePropertyChanged(string propertyName) {System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;if ((propertyChanged != null)) {propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));}}}[DataContract(Namespace = "http://opcfoundation.org/webservices/XMLDA/1.0/", Name = "OPCError")]公共类 OPCError:System.ComponentModel.INotifyPropertyChanged {私有字符串文本字段;私有 System.Xml.XmlQualifiedName idField;[DataMember(Name = "Text", Order = 0)]公共字符串文本{得到 {返回 this.textField;}放 {this.textField = 值;this.RaisePropertyChanged("Text");}}[DataMember(Name = "ID", Order = 1)]公共 System.Xml.XmlQualifiedName ID {得到 {返回 this.idField;}放 {this.idField = 值;this.RaisePropertyChanged("ID");}}公共事件 System.ComponentModel.PropertyChangedEventHandler PropertyChanged;protected void RaisePropertyChanged(string propertyName) {System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;if ((propertyChanged != null)) {propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));}}}

C) WSDL(一部分,涉及类型定义的部分)

<xs:元素名称="浏览"><xs:complexType><xs:sequence/></xs:complexType></xs:element><xs:element name="BrowseResponse"><xs:complexType><xs:sequence/></xs:complexType></xs:element><xs:element name="GetProperties"><xs:complexType><xs:sequence/></xs:complexType></xs:element><xs:element name="GetPropertiesResponse"><xs:complexType><xs:sequence/></xs:complexType></xs:element><xs:element name="GetStatus"><xs:complexType><xs:sequence/></xs:complexType></xs:element><xs:element name="GetStatusResponse"><xs:complexType><xs:sequence/></xs:complexType></xs:element><xs:element name="读取"><xs:complexType><xs:sequence/></xs:complexType></xs:element><xs:element name="ReadResponse"><xs:complexType><xs:sequence/></xs:complexType></xs:element><xs:element name="订阅"><xs:complexType><xs:sequence/></xs:complexType></xs:element><xs:element name="订阅响应"><xs:complexType><xs:sequence/></xs:complexType></xs:element><xs:element name="订阅取消"><xs:complexType><xs:sequence/></xs:complexType></xs:element><xs:element name="SubscriptionCancelResponse"><xs:complexType><xs:sequence/></xs:complexType></xs:element><xs:element name="SubscriptionPolledRefresh"><xs:complexType><xs:sequence/></xs:complexType></xs:element><xs:element name="SubscriptionPolledRefreshResponse"><xs:complexType><xs:sequence/></xs:complexType></xs:element><xs:element name="Write">-<xs:complexType><xs:sequence/></xs:complexType></xs:element><xs:element name="WriteResponse"><xs:complexType><xs:sequence/></xs:complexType></xs:element></xs:schema>

上面的部分包含在这里:

<wsdl:类型><xsd:schema targetNamespace="http://opcfoundation.org/webservices/XMLDA/1.0/Imports"><xsd:import namespace="http://opcfoundation.org/webservices/XMLDA/1.0/" schemaLocation="http://localhost/OCXS/OCXS.svc?xsd=xsd0"/></xsd:架构></wsdl:types><wsdl:message name="BrowseRequest"><wsdl:part name="parameters" element="tns:Browse"/></wsdl:message><wsdl:message name="BrowseResponse"><wsdl:part name="parameters" element="tns:BrowseResponse"/></wsdl:message><wsdl:message name="GetPropertiesRequest"><wsdl:part name="parameters" element="tns:GetProperties"/></wsdl:message><wsdl:message name="GetPropertiesResponse"><wsdl:part name="parameters" element="tns:GetPropertiesResponse"/></wsdl:message><wsdl:message name="GetStatusRequest"><wsdl:part name="parameters" element="tns:GetStatus"/></wsdl:message><wsdl:message name="GetStatusResponse"><wsdl:part name="parameters" element="tns:GetStatusResponse"/></wsdl:message><wsdl:message name="ReadRequest"><wsdl:part name="parameters" element="tns:Read"/></wsdl:message>-<wsdl:message name="ReadResponse"><<wsdl:part name="parameters" element="tns:ReadResponse"/></wsdl:message><wsdl:message name="SubscribeRequest"><wsdl:part name="parameters" element="tns:Subscribe"/></wsdl:message><wsdl:message name="SubscribeResponse"><wsdl:part name="parameters" element="tns:SubscribeResponse"/></wsdl:message><wsdl:message name="SubscriptionCancelRequest"><wsdl:part name="parameters" element="tns:SubscriptionCancel"/></wsdl:message><wsdl:message name="SubscriptionCancelResponse">;<wsdl:part name="parameters" element="tns:SubscriptionCancelResponse"/></wsdl:message><wsdl:message name="SubscriptionPolledRefreshRequest"><wsdl:part name="parameters" element="tns:SubscriptionPolledRefresh"/></wsdl:message><wsdl:message name="SubscriptionPolledRefreshResponse"><wsdl:part name="parameters" element="tns:SubscriptionPolledRefreshResponse"/></wsdl:message><wsdl:message name="WriteRequest"><wsdl:part name="parameters" element="tns:Write"/></wsdl:message>-<wsdl:message name="WriteResponse"><<wsdl:part name="parameters" element="tns:WriteResponse"/></wsdl:message><wsdl:portType name="IOCXSService">-<wsdl:operation name="Browse"><wsdl:input name="BrowseRequest" message="tns:BrowseRequest" wsaw:Action="http:///opcfoundation.org/webservices/XMLDA/1.0/Browse"/><wsdl:output name="BrowseResponse" message="tns:BrowseResponse" wsaw:Action="http://opcfoundation.org/webservices/XMLDA/1.0/IOCXSService/BrowseResponse"/></wsdl:operation><wsdl:operation name="GetProperties"><wsdl:input name="GetPropertiesRequest" message="tns:GetPropertiesRequest" wsaw:Action="http://opcfoundation.org/webservices/XMLDA/1.0/GetProperties"/><wsdl:output name="GetPropertiesResponse" message="tns:GetPropertiesResponse" wsaw:Action="http://opcfoundation.org/webservices/XMLDA/1.0/IOCXSService/GetPropertiesResponse"/></wsdl:操作><wsdl:operation name="GetStatus"><wsdl:input name="GetStatusRequest" message="tns:GetStatusRequest" wsaw:Action="http://opcfoundation.org/webservices/XMLDA/1.0/GetStatus"/><wsdl:output name="GetStatusResponse" message="tns:GetStatusResponse" wsaw:Action="http://opcfoundation.org/webservices/XMLDA/1.0/IOCXSService/GetStatusResponse"/></wsdl:操作><wsdl:operation name="Read"><wsdl:input name="ReadRequest" message="tns:ReadRequest" wsaw:Action="http://opcfoundation.org/webservices/XMLDA/1.0/Read"/><wsdl:output name="ReadResponse" message="tns:ReadResponse" wsaw:Action="http://opcfoundation.org/webservices/XMLDA/1.0/IOCXSService/ReadResponse"/></wsdl:operation>-<wsdl:operation name="Subscribe"><wsdl:input name="SubscribeRequest" message="tns:SubscribeRequest" wsaw:Action="http://opcfoundation.org/webservices/XMLDA/1.0/Subscribe"/><wsdl:output name="SubscribeResponse" message="tns:SubscribeResponse" wsaw:Action="http://opcfoundation.org/webservices/XMLDA/1.0/IOCXSService/SubscribeResponse"/></wsdl:操作><wsdl:operation name="SubscriptionCancel"><wsdl:input name="SubscriptionCancelRequest" message="tns:SubscriptionCancelRequest" wsaw:Action="http://opcfoundation.org/webservices/XMLDA/1.0/SubscriptionCancel"/><wsdl:output name="SubscriptionCancelResponse" message="tns:SubscriptionCancelResponse" wsaw:Action="http://opcfoundation.org/webservices/XMLDA/1.0/IOCXSService/SubscriptionCancelResponse"/></wsdl:操作><wsdl:operation name="SubscriptionPolledRefresh"><wsdl:input name="SubscriptionPolledRefreshRequest" message="tns:SubscriptionPolledRefreshRequest" wsaw:Action="http://opcfoundation.org/webservices/XMLDA/1.0/SubscriptionPolledRefresh"/><wsdl:output name="SubscriptionPolledRefreshResponse" message="tns:SubscriptionPolledRefreshResponse" wsaw:Action="http://opcfoundation.org/webservices/XMLDA/1.0/IOCXSService/SubscriptionPolledRefreshResponse"/></wsdl:操作><wsdl:operation name="Write"><wsdl:input name="WriteRequest" message="tns:WriteRequest" wsaw:Action="http://opcfoundation.org/webservices/XMLDA/1.0/Write"/><wsdl:output name="WriteResponse" message="tns:WriteResponse" wsaw:Action="http://opcfoundation.org/webservices/XMLDA/1.0/IOCXSService/WriteResponse"/></wsdl:操作></wsdl:portType></wsdl:definitions>

注意:如果我从 BrowseResponseBrowseRequest 中删除 MessageContract 属性(两者都删除了,否则运行时会变得疯狂),问题仍然存在......真的是消息契约的问题吗???

也许是解决方案

好吧,大家,也许我能看到光...如果我删除所有 DataContract(s) 和 ServiceContract(s) 属性命名空间和名称(总是没有 MessageContract(s)),一切正常.好吧,我得到了 wsdl 和类型,但即使使用它们也无法工作(但总是没有 MessageContract(s)).这就是原因(我想得到你的确认):

我指定的命名空间:http://opcfoundation.org/webservices/XMLDA/1.0/ 不是一个简单的名字,好吧,在这里你可以找到我的操作和类型(已经定义)的 WSDL 定义.我的 svc 没有生成完整的 WSDL 定义类型,因为它已经在我提供的命名空间中定义了!!!

您对此有何看法?

解决方案

除了 [DataContract] 之外,您还将 BrowseResponse 类定义为 [MessageContract].根据您的说法,似乎 [MessageContract] 优先(这是有道理的 - [MC] 定义了消息的 SOAP 信封,其中可以包含 成员,这些成员可以是数据合同.消息合同的成员使用 [MessageHeader][MessageBodyMember] 属性定义,并且由于您没有任何属性,因此合同基本上是空的.>

您没有显示 BrowseRequest 的定义,但由于您在请求中使用 [MC] 类型,因此您还需要在响应中使用 [MC],所以我假设它具有相同的问题.

I am writing a web service using WCF.

  1. I created data contracts.

  2. I created my service contract (interface). I defined methods (whose parameters are typed as for the data contracts).

  3. I implemented the service contract creating a service class.

  4. I hosted my service using a svc file and IIS.

  5. I tried my service, looked for http://localhost/myvirtdiriis/myservice.svc --> The service was loaded, and a nice web page describing the presence of my service showed.

  6. I wanted to look at the WSDL. Using the provided link I can see that types are only defined, I can see just the types definition (like <complexType>), but nothing inside (types are empty).

  7. I coded a simple client, a call to an operation went good, but when returning the type it is empty (internal fields have the construction values, while my service place some values there), for example, a call to an operation returning a type having three strings set by the operation contract method to "Hello", "Hello2" and "Hello3", returns the type having these strings set to "" (construction values, as if no changes happened).

What happened?

It seems that serialization fails.

I am providing some:

A1) A part of the service contract:

[ServiceContract(Namespace = "http://opcfoundation.org/webservices/XMLDA/1.0/")]
   public interface IOCXSService {
      [OperationContract(Action = "http://opcfoundation.org/webservices/XMLDA/1.0/Browse")]
      BrowseResponse Browse(BrowseRequest request);
      ...
}

A2) The service implementation:

public class MyService : IOCXSService {
      ...
      public BrowseResponse Browse(BrowseRequest request) {
         ...
      }
      ...
   }

B) Types:

[DataContract(Namespace = "http://opcfoundation.org/webservices/XMLDA/1.0/", Name = "BrowseResponse")]
    [System.ServiceModel.MessageContractAttribute(WrapperName = "BrowseResponse", WrapperNamespace = "http://opcfoundation.org/webservices/XMLDA/1.0/", IsWrapped = true)]
    public class BrowseResponse {

        [DataMember(Name = "BrowseResult", Order = 0)]
        public OCXS.OCXSServiceLibrary.OPCXMLDA10.ReplyBase BrowseResult;

        [DataMember(Name = "Elements", Order = 1)]
        public BrowseElement[] Elements;

        [DataMember(Name = "Errors", Order = 2)]
        public OPCError[] Errors;

        [DataMember(Name = "ContinuationPoint", Order = 3)]
        public string ContinuationPoint;

        [DataMember(Name = "MoreElements", Order = 4)]
        public bool MoreElements;

        public BrowseResponse() {
        }

        public BrowseResponse(OCXS.OCXSServiceLibrary.OPCXMLDA10.ReplyBase BrowseResult, BrowseElement[] Elements, OPCError[] Errors, string ContinuationPoint, bool MoreElements) {
            this.BrowseResult = BrowseResult;
            this.Elements = Elements;
            this.Errors = Errors;
            this.ContinuationPoint = ContinuationPoint;
            this.MoreElements = MoreElements;
        }

[DataContract(Namespace = "http://opcfoundation.org/webservices/XMLDA/1.0/", Name = "ReplyBase")]
    public class ReplyBase : System.ComponentModel.INotifyPropertyChanged {

        private System.DateTime rcvTimeField;

        private System.DateTime replyTimeField;

        private string clientRequestHandleField;

        private string revisedLocaleIDField;

        private serverState serverStateField;

        [DataMember(Name = "RcvTime", Order = 0)]
        public System.DateTime RcvTime {
            get {
                return this.rcvTimeField;
            }
            set {
                this.rcvTimeField = value;
                this.RaisePropertyChanged("RcvTime");
            }
        }

        [DataMember(Name = "ReplyTime", Order = 1)]
        public System.DateTime ReplyTime {
            get {
                return this.replyTimeField;
            }
            set {
                this.replyTimeField = value;
                this.RaisePropertyChanged("ReplyTime");
            }
        }

        [DataMember(Name = "ClientRequestHandle", Order = 2)]
        public string ClientRequestHandle {
            get {
                return this.clientRequestHandleField;
            }
            set {
                this.clientRequestHandleField = value;
                this.RaisePropertyChanged("ClientRequestHandle");
            }
        }

        [DataMember(Name = "RevisedLocaleID", Order = 3)]
        public string RevisedLocaleID {
            get {
                return this.revisedLocaleIDField;
            }
            set {
                this.revisedLocaleIDField = value;
                this.RaisePropertyChanged("RevisedLocaleID");
            }
        }

        [DataMember(Name = "ServerState", Order = 4)]
        public serverState ServerState {
            get {
                return this.serverStateField;
            }
            set {
                this.serverStateField = value;
                this.RaisePropertyChanged("ServerState");
            }
        }

        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propertyName) {
            System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
            if ((propertyChanged != null)) {
                propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
            }
        }
    }

[DataContract(Namespace = "http://opcfoundation.org/webservices/XMLDA/1.0/", Name = "BrowseElement")]
    public class BrowseElement : INotifyPropertyChanged {

        private ItemProperty[] propertiesField;

        private string nameField;

        private string itemPathField;

        private string itemNameField;

        private bool isItemField;

        private bool hasChildrenField;

        [DataMember(Name = "Properties", Order = 0)]
        public ItemProperty[] Properties {
            get {
                return this.propertiesField;
            }
            set {
                this.propertiesField = value;
                this.RaisePropertyChanged("Properties");
            }
        }

        [DataMember(Name = "Name", Order = 1)]
        public string Name {
            get {
                return this.nameField;
            }
            set {
                this.nameField = value;
                this.RaisePropertyChanged("Name");
            }
        }

        [DataMember(Name = "ItemPath", Order = 2)]
        public string ItemPath {
            get {
                return this.itemPathField;
            }
            set {
                this.itemPathField = value;
                this.RaisePropertyChanged("ItemPath");
            }
        }

        [DataMember(Name = "ItemName", Order = 3)]
        public string ItemName {
            get {
                return this.itemNameField;
            }
            set {
                this.itemNameField = value;
                this.RaisePropertyChanged("ItemName");
            }
        }

        [DataMember(Name = "IsItem", Order = 4)]
        public bool IsItem {
            get {
                return this.isItemField;
            }
            set {
                this.isItemField = value;
                this.RaisePropertyChanged("IsItem");
            }
        }

        [DataMember(Name = "HasChildren", Order = 5)]
        public bool HasChildren {
            get {
                return this.hasChildrenField;
            }
            set {
                this.hasChildrenField = value;
                this.RaisePropertyChanged("HasChildren");
            }
        }

        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propertyName) {
            System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
            if ((propertyChanged != null)) {
                propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
            }
        }

    }

[DataContract(Namespace = "http://opcfoundation.org/webservices/XMLDA/1.0/", Name = "OPCError")]
    public class OPCError : System.ComponentModel.INotifyPropertyChanged {

        private string textField;

        private System.Xml.XmlQualifiedName idField;

        [DataMember(Name = "Text", Order = 0)]
        public string Text {
            get {
                return this.textField;
            }
            set {
                this.textField = value;
                this.RaisePropertyChanged("Text");
            }
        }

        [DataMember(Name = "ID", Order = 1)]
        public System.Xml.XmlQualifiedName ID {
            get {
                return this.idField;
            }
            set {
                this.idField = value;
                this.RaisePropertyChanged("ID");
            }
        }

        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propertyName) {
            System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
            if ((propertyChanged != null)) {
                propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
            }
        }
    }

C) WSDL (a part, the one concerning type definitions)

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:tns="http://opcfoundation.org/webservices/XMLDA/1.0/" targetNamespace="http://opcfoundation.org/webservices/XMLDA/1.0/" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="Browse">
      <xs:complexType>
         <xs:sequence/>
      </xs:complexType>
   </xs:element>
   <xs:element name="BrowseResponse">
      <xs:complexType>
         <xs:sequence/>
      </xs:complexType>
   </xs:element>
   <xs:element name="GetProperties">
      <xs:complexType>
         <xs:sequence/>
      </xs:complexType>
   </xs:element>
   <xs:element name="GetPropertiesResponse">
      <xs:complexType>
         <xs:sequence/>
      </xs:complexType>
   </xs:element>
   <xs:element name="GetStatus">
      <xs:complexType>
         <xs:sequence/>
      </xs:complexType>
   </xs:element>
   <xs:element name="GetStatusResponse">
      <xs:complexType>
         <xs:sequence/>
      </xs:complexType>
   </xs:element>
   <xs:element name="Read">
      <xs:complexType>
         <xs:sequence/>
      </xs:complexType>
   </xs:element>
   <xs:element name="ReadResponse">
      <xs:complexType>
         <xs:sequence/>
      </xs:complexType>
   </xs:element>
   <xs:element name="Subscribe">
      <xs:complexType>
         <xs:sequence/>
      </xs:complexType>
   </xs:element>
   <xs:element name="SubscribeResponse">
      <xs:complexType>
         <xs:sequence/>
      </xs:complexType>
   </xs:element>
   <xs:element name="SubscriptionCancel">
      <xs:complexType>
         <xs:sequence/>
      </xs:complexType>
   </xs:element>
   <xs:element name="SubscriptionCancelResponse">
      <xs:complexType>
         <xs:sequence/>
      </xs:complexType>
   </xs:element>
   <xs:element name="SubscriptionPolledRefresh">
      <xs:complexType>
         <xs:sequence/>
      </xs:complexType>
   </xs:element>
   <xs:element name="SubscriptionPolledRefreshResponse">
      <xs:complexType>
         <xs:sequence/>
      </xs:complexType>
   </xs:element>
   <xs:element name="Write">-<xs:complexType><xs:sequence/></xs:complexType></xs:element>
      <xs:element name="WriteResponse">
         <xs:complexType>
         <xs:sequence/>
      </xs:complexType>
   </xs:element>
</xs:schema>

The piece above is included here:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:tns="http://opcfoundation.org/webservices/XMLDA/1.0/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://opcfoundation.org/webservices/XMLDA/1.0/">
<wsdl:types>
<xsd:schema targetNamespace="http://opcfoundation.org/webservices/XMLDA/1.0/Imports">
<xsd:import namespace="http://opcfoundation.org/webservices/XMLDA/1.0/" schemaLocation="http://localhost/OCXS/OCXS.svc?xsd=xsd0"/></xsd:schema></wsdl:types>
<wsdl:message name="BrowseRequest"><wsdl:part name="parameters" element="tns:Browse"/></wsdl:message>
<wsdl:message name="BrowseResponse"><wsdl:part name="parameters" element="tns:BrowseResponse"/></wsdl:message>
<wsdl:message name="GetPropertiesRequest"><wsdl:part name="parameters" element="tns:GetProperties"/></wsdl:message>
<wsdl:message name="GetPropertiesResponse"><wsdl:part name="parameters" element="tns:GetPropertiesResponse"/></wsdl:message>
<wsdl:message name="GetStatusRequest"><wsdl:part name="parameters" element="tns:GetStatus"/></wsdl:message>
<wsdl:message name="GetStatusResponse"><wsdl:part name="parameters" element="tns:GetStatusResponse"/></wsdl:message>
<wsdl:message name="ReadRequest"><wsdl:part name="parameters" element="tns:Read"/></wsdl:message>-<wsdl:message name="ReadResponse"><wsdl:part name="parameters" element="tns:ReadResponse"/></wsdl:message>
<wsdl:message name="SubscribeRequest"><wsdl:part name="parameters" element="tns:Subscribe"/></wsdl:message>
<wsdl:message name="SubscribeResponse"><wsdl:part name="parameters" element="tns:SubscribeResponse"/></wsdl:message>
<wsdl:message name="SubscriptionCancelRequest"><wsdl:part name="parameters" element="tns:SubscriptionCancel"/></wsdl:message><wsdl:message name="SubscriptionCancelResponse"><wsdl:part name="parameters" element="tns:SubscriptionCancelResponse"/></wsdl:message>
<wsdl:message name="SubscriptionPolledRefreshRequest"><wsdl:part name="parameters" element="tns:SubscriptionPolledRefresh"/></wsdl:message>
<wsdl:message name="SubscriptionPolledRefreshResponse"><wsdl:part name="parameters" element="tns:SubscriptionPolledRefreshResponse"/></wsdl:message>
<wsdl:message name="WriteRequest"><wsdl:part name="parameters" element="tns:Write"/></wsdl:message>-<wsdl:message name="WriteResponse"><wsdl:part name="parameters" element="tns:WriteResponse"/></wsdl:message>
<wsdl:portType name="IOCXSService">-<wsdl:operation name="Browse"><wsdl:input name="BrowseRequest" message="tns:BrowseRequest" wsaw:Action="http://opcfoundation.org/webservices/XMLDA/1.0/Browse"/><wsdl:output name="BrowseResponse" message="tns:BrowseResponse" wsaw:Action="http://opcfoundation.org/webservices/XMLDA/1.0/IOCXSService/BrowseResponse"/></wsdl:operation>
<wsdl:operation name="GetProperties"><wsdl:input name="GetPropertiesRequest" message="tns:GetPropertiesRequest" wsaw:Action="http://opcfoundation.org/webservices/XMLDA/1.0/GetProperties"/><wsdl:output name="GetPropertiesResponse" message="tns:GetPropertiesResponse" wsaw:Action="http://opcfoundation.org/webservices/XMLDA/1.0/IOCXSService/GetPropertiesResponse"/></wsdl:operation>
<wsdl:operation name="GetStatus"><wsdl:input name="GetStatusRequest" message="tns:GetStatusRequest" wsaw:Action="http://opcfoundation.org/webservices/XMLDA/1.0/GetStatus"/><wsdl:output name="GetStatusResponse" message="tns:GetStatusResponse" wsaw:Action="http://opcfoundation.org/webservices/XMLDA/1.0/IOCXSService/GetStatusResponse"/></wsdl:operation>
<wsdl:operation name="Read"><wsdl:input name="ReadRequest" message="tns:ReadRequest" wsaw:Action="http://opcfoundation.org/webservices/XMLDA/1.0/Read"/><wsdl:output name="ReadResponse" message="tns:ReadResponse" wsaw:Action="http://opcfoundation.org/webservices/XMLDA/1.0/IOCXSService/ReadResponse"/></wsdl:operation>-<wsdl:operation name="Subscribe"><wsdl:input name="SubscribeRequest" message="tns:SubscribeRequest" wsaw:Action="http://opcfoundation.org/webservices/XMLDA/1.0/Subscribe"/><wsdl:output name="SubscribeResponse" message="tns:SubscribeResponse" wsaw:Action="http://opcfoundation.org/webservices/XMLDA/1.0/IOCXSService/SubscribeResponse"/></wsdl:operation>
<wsdl:operation name="SubscriptionCancel"><wsdl:input name="SubscriptionCancelRequest" message="tns:SubscriptionCancelRequest" wsaw:Action="http://opcfoundation.org/webservices/XMLDA/1.0/SubscriptionCancel"/><wsdl:output name="SubscriptionCancelResponse" message="tns:SubscriptionCancelResponse" wsaw:Action="http://opcfoundation.org/webservices/XMLDA/1.0/IOCXSService/SubscriptionCancelResponse"/></wsdl:operation>
<wsdl:operation name="SubscriptionPolledRefresh"><wsdl:input name="SubscriptionPolledRefreshRequest" message="tns:SubscriptionPolledRefreshRequest" wsaw:Action="http://opcfoundation.org/webservices/XMLDA/1.0/SubscriptionPolledRefresh"/><wsdl:output name="SubscriptionPolledRefreshResponse" message="tns:SubscriptionPolledRefreshResponse" wsaw:Action="http://opcfoundation.org/webservices/XMLDA/1.0/IOCXSService/SubscriptionPolledRefreshResponse"/></wsdl:operation>
<wsdl:operation name="Write"><wsdl:input name="WriteRequest" message="tns:WriteRequest" wsaw:Action="http://opcfoundation.org/webservices/XMLDA/1.0/Write"/><wsdl:output name="WriteResponse" message="tns:WriteResponse" wsaw:Action="http://opcfoundation.org/webservices/XMLDA/1.0/IOCXSService/WriteResponse"/></wsdl:operation></wsdl:portType></wsdl:definitions>

NOTE: If I remove the MessageContract attribute from BrowseResponse and BrowseRequest (both removed otherwose the runtime gets crazy), the problem persists.... Is it really an issue concerning messagecontracts???

MAYBE THE SOLUTION

OK everybody, maybe I can see the light... If I remove all DataContract(s) and ServiceContract(s) attributes namespace and names (always without MessageContract(s)), everything works. Well, I get wsdl and types, but t worked even with them (but always without MessageContract(s)). Here's why (I would like to get confirm from you):

The namespace I specified: http://opcfoundation.org/webservices/XMLDA/1.0/ is not a simple name, well, here you can find WSDL definitions for my operations and types (already defined). My svc does not generate complete WSDL definitions with types BECAUSE IT ALREADY HAS THEM defined in that namespace I provided!!!

What do you think about this?

解决方案

You defined the class BrowseResponse as a [MessageContract], in addition to [DataContract]. Based on what you're saying, it seems like [MessageContract] takes precedence (which makes sense - [MC] defines the SOAP envelope for the message, which can contain members, and those members can be data contracts. Members of message contracts are defined with either [MessageHeader] or [MessageBodyMember] attributes, and since you don't have any, the contract is essentially empty.

You didn't show the definition of BrowseRequest, but since you're using a [MC] type in the request, you also need to use a [MC] in the response, so I'm assuming it has the same problem.

这篇关于.NET WCF 服务的类型序列化问题:服务 WSDL 在 XSD 中定义空类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆