返回肥皂信封缺失值

时间:2013-01-17 15:34:32

标签: c# soap wsdl generic-collections

我有一个Soap WSDL,在我的应用程序中设置为指向.asmx文件的服务引用。我的响应肥皂信封问题。我有一个集合对象,当它在我的接收代码上创建时,值就在那里。当我逐步完成代码到soap包围现在是一个内存流并且即将被发送回调用客户端时,将填充该集合。然而,还有一次按F10并且我回到了调用客户端,收集了空集。

这是我正在使用的类的WSDL:

     <complexType name="Step">
    <complexContent>
      <extension base="tns:APIObject">
        <sequence>
          <element name="StepType" minOccurs="0" maxOccurs="1" type="xsd:string" />
          <element name="Name" minOccurs="0" maxOccurs="1" type="xsd:string" />
          <element name="Description" minOccurs="0" maxOccurs="1" type="xsd:string" />
          <element name="Automation" minOccurs="0" type="tns:Automation" />
          <element name="Sequence" minOccurs="0" type="xsd:int" />
          <element name="Activities" minOccurs="0" maxOccurs="1">
            <complexType>
              <sequence>
                <element name="Activity" type="tns:AutomationActivity" minOccurs="0"    maxOccurs="unbounded" />
              </sequence>
            </complexType>
          </element>
        </sequence>
      </extension>
    </complexContent>
  </complexType>
  <complexType name="StepInstance">
    <complexContent>
      <extension base="tns:Step">
        <sequence>
          <element name="StepDefinition" type="tns:Step" minOccurs="0" />
          <element name="AutomationInstance" type="tns:AutomationInstance" minOccurs="0" />
          <element name="ActivityInstances" minOccurs="0">
            <complexType>
              <sequence>
                <element name="ActivityInstance" type="tns:AutomationActivityInstance" minOccurs="0" maxOccurs="unbounded" />
              </sequence>
            </complexType>
          </element>
        </sequence>
      </extension>
    </complexContent>
  </complexType>
  <complexType name="AutomationActivity">
    <complexContent>
      <extension base="tns:APIObject">
        <sequence>
          <element name="Name" minOccurs="0" maxOccurs="1" type="xsd:string" />
          <element name="Description" minOccurs="0" maxOccurs="1" type="xsd:string" />
          <element name="IsActive" minOccurs="0" maxOccurs="1" type="xsd:boolean" />
          <element name="Definition" minOccurs="0" maxOccurs="1" type="tns:APIObject" />
          <element name="Automation" minOccurs="0" type="tns:Automation" />
          <element name="Step" minOccurs="0" type="tns:Step" />
          <element name="Sequence" minOccurs="0" type="xsd:int" />
          <element name="ActivityObject" minOccurs="0" type="tns:APIObject" />
        </sequence>
      </extension>
    </complexContent>
  </complexType>
  <complexType name="AutomationActivityInstance">
    <complexContent>
      <extension base="tns:AutomationActivity">
        <sequence>
          <element name="ActivityID" type="xsd:string" minOccurs="0" maxOccurs="1"></element>
          <element name="AutomationID" minOccurs="0" maxOccurs="1" type="xsd:string" />
          <element name="SequenceID" minOccurs="0" maxOccurs="1" type="xsd:int" />
          <element name="Status" minOccurs="0" maxOccurs="1" type="xsd:int" />
          <element name="StatusLastUpdate" minOccurs="0" maxOccurs="1" type="xsd:dateTime" />
          <element name="StatusMessage" type="xsd:string" minOccurs="0" />
          <element name="ActivityDefinition" type="tns:AutomationActivity" minOccurs="0" />
          <element name="AutomationInstance" type="tns:AutomationInstance" minOccurs="0" />
          <element name="StepInstance" type="tns:StepInstance" minOccurs="0" />
          <element name="ScheduledTime" minOccurs="0" maxOccurs="1" type="xsd:dateTime" />
          <element name="StartTime" minOccurs="0" maxOccurs="1" type="xsd:dateTime" />
          <element name="CompletedTime" minOccurs="0" maxOccurs="1" type="xsd:dateTime" />
        </sequence>
      </extension>
    </complexContent>
  </complexType>

以下是序列化之前的响应Envelop并转换为MemoryStream

    <soap:Body xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<RetrieveResponseMsg xmlns="">   <OverallStatus>MoreDataAvailable</OverallStatus>
<RequestID>0216f0bb-9d4a-455f-8517-5856f2e6f65d</RequestID>
<Results xsi:type="AutomationInstance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<PartnerKey xsi:nil="true" />
<CreatedDate>2013-01-11T12:18:20.453</CreatedDate>
<ModifiedDate>2013-01-11T12:18:25.27</ModifiedDate>
<ObjectID xsi:nil="true" />
<CustomerKey>0aeb9113-14ac-f480-cb35-efaf4439dd34</CustomerKey>
<IsPlatformObject>true</IsPlatformObject>
<Name></Name>
<Description/>
<InteractionObjectID>7c9a50f8-645d-48f2-a023-9aea4a31e294</InteractionObjectID>
<IsActive>false</IsActive>
<ScheduledTime>2013-01-11T12:01:53.543</ScheduledTime>
<AutomationID>7c9a50f8-645d-48f2-a023-9aea4a31e294</AutomationID>
<StepInstances>
    <StepInstance>
        <PartnerKey xsi:nil="true" />
        <ObjectID xsi:nil="true" />
        <StepDefinition>
            <PartnerKey xsi:nil="true" />
            <ObjectID xsi:nil="true" />
            <Name />
            <Description />
            <Sequence>0</Sequence>
            <Activities><Activity>
            <PartnerKeyxsi:nil="true"/>
            <PartnerProperties>     
                <Name>PartnerApiObjectTypeId</Name>  <Value>42</Value>  </PartnerProperties>
            <CreatedDate>2013-01-11T12:00:20.767</CreatedDate>
            <ObjectID>9e34164a-5089-4fe3-aee3-33f0a472de6f</ObjectID>
            <CustomerKey>ebf044ef-8266-433f-b424-cc0aeb3735bd</CustomerKey>
            <Name>test</Name>
            <Description />
            <IsActive>true</IsActive>
            </Activity></Activities>
        </StepDefinition>
    </StepInstance>
</StepInstances>
<StartTime>2013-01-11T12:18:20.447</StartTime>
<CompletedTime>2013-01-11T12:18:25.27</CompletedTime>
</Results>
</RetrieveResponseMsg>
    </soap:Body>

StepInstances是专注于我的问题的集合。如您所见,它按预期填充。

这是MemoryStream转换回信封

    <?xml version=\"1.0\" encoding=\"utf-8\"?>
<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">    
<soap:Header>                           <wsa:Action>RetrieveResponse</wsa:Action>
<wsa:MessageID>urn:uuid:a470ddfb-e032-4291-90e2-ce8ffb2b6a12</wsa:MessageID>
<wsa:RelatesTo>urn:uuid:4b5f3202-2207-4691-b33c-36f8a8ff799f</wsa:RelatesTo>
<wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
<wsse:Security>     
<wsu:Timestampwsu:Id=\"Timestamp-4464e3e0-c473-45e8-865f-21b8a0134927\">
<wsu:Created>2013-01-16T22:04:18Z</wsu:Created>
<wsu:Expires>2013-01-16T22:09:18Z</wsu:Expires>
</wsu:Timestamp>
</wsse:Security>
</soap:Header>
<soap:Body>
<RetrieveResponseMsg xmlns=\"">
<OverallStatus>MoreDataAvailable</OverallStatus>
<RequestID>e25b58e1-5ad7-4cf6-862b-429354f92aca</RequestID>
<Results xsi:type=\"AutomationInstance\">
<PartnerKey xsi:nil=\"true\" />
<CreatedDate>2013-01-11T12:18:20.453</CreatedDate>
<ModifiedDate>2013-01-11T12:18:25.27</ModifiedDate>
<ObjectID xsi:nil=\"true\" />
<CustomerKey>0aeb9113-14ac-f480-cb35-efaf4439dd34</CustomerKey>
<IsPlatformObject>true</IsPlatformObject>
<Name></Name>
<Description/>
<InteractionObjectID>7c9a50f8-645d-48f2-a023-9aea4a31e294</InteractionObjectID>
<IsActive>false</IsActive>
<ScheduledTime>2013-01-11T12:01:53.543</ScheduledTime>
<AutomationID>7c9a50f8-645d-48f2-a023-9aea4a31e294</AutomationID>
<StepInstances>
    <StepInstance>
        <PartnerKey xsi:nil=\"true\" />
        <ObjectID xsi:nil=\"true\" />
        <StepDefinition>
            <PartnerKey xsi:nil=\"true\" />
            <ObjectID xsi:nil=\"true\" />
            <Name />
            <Description />
            <Sequence>0</Sequence>
            <Activities><Activity>
            <PartnerKey xsi:nil=\"true\" />
            <PartnerProperties>
            <Name>PartnerApiObjectTypeId</Name><Value>42</Value>
            </PartnerProperties>
            <CreatedDate>2013-01-11T12:00:20.767</CreatedDate>
            <ObjectID>9e34164a-5089-4fe3-aee3-33f0a472de6f</ObjectID>
            <CustomerKey>ebf044ef-8266-433f-b424-cc0aeb3735bd</CustomerKey>
            <Name>test</Name>
            <Description/>
            <IsActive>true</IsActive></Activity></Activities>       
            </StepDefinition>
            </StepInstance>
            </StepInstances>
            <StartTime>2013-01-11T12:18:20.447</StartTime>
            <CompletedTime>2013-01-11T12:18:25.27</CompletedTime>
            </Results>
    </RetrieveResponseMsg>
</soap:Body>

进入MemoryStream后,它会被发送回调用客户端。我在其中查看对象,StepInstances为null。

另请注意,我发布的WSDL是一部分,主要是违规类。返回的信封是一个包含这些类的更大的类,并且发布的内容太多了。

但是我从接收客户端进入内存流的最后一段代码已填充。接下来的f10我用我的对象回到了我的调用客户端,收集为空。

希望这是有道理的,有人可以对此有所了解。您需要的更多数据我将尝试发布。

另外值得注意的是,我有权访问的是.wsdl文件,而不是实际的WCF项目或类。

配置我的服务参考:对于集合类型,我选择了Generic.List,而字典类型I选择了Generic.Dictionary。

更新:wsdl中的APIObject看起来像这样

    <complexType name="APIObject">
    <sequence>
      <element name="Client" type="tns:ClientID" minOccurs="0" maxOccurs="1"></element>
      <element name="PartnerKey" type="xsd:string" nillable="true" minOccurs="0" maxOccurs="1"></element>
      <element name="PartnerProperties" type="tns:APIProperty" minOccurs="0" maxOccurs="unbounded"></element>
      <element name="CreatedDate" type="xsd:dateTime" minOccurs="0" maxOccurs="1"></element>
      <element name="ModifiedDate" type="xsd:dateTime" minOccurs="0" maxOccurs="1" nillable="true"></element>
      <element name="ID" type="xsd:int" minOccurs="0" maxOccurs="1"></element>
      <element name="ObjectID" type="xsd:string" nillable="true" minOccurs="0" maxOccurs="1"></element>
      <element name="CustomerKey" type="xsd:string" minOccurs="0" maxOccurs="1"></element>
      <element name="Owner" type="tns:Owner" minOccurs="0" maxOccurs="1"></element>
      <element name="CorrelationID" minOccurs="0" type="xsd:string" />
      <element name="ObjectState" type="xsd:string" minOccurs="0" maxOccurs="1"></element>
      <element name="IsPlatformObject" minOccurs="0" maxOccurs="1" type="xsd:boolean" />
    </sequence>
  </complexType>

更新#2:我猜错了它是WCF,我只能访问.wsdl文件,编译后我将服务引用指向.asmx文件。

1 个答案:

答案 0 :(得分:0)

我已经看到了各种SOAP客户端应用程序的问题,就像您描述的那样,当序列化为SOAP响应的原始类是直接对象引用而不使用Getter / Setter属性时。所以如果你做的事情如下:

[Serializable()]
public List<StepInstance> StepInstances = new List<StepInstance>;

...

[Serializable()]
public class StepInstance {
    public string PartnerKey = "";
    public string ObjectID = "";
}

...对于某些类型的客户,这有时似乎不适用。相反,确保对象使用公共getter / setter方法,并且在客户端反序列化对象时出现的问题可能会很快消失。不知道为什么会这样,但似乎对某些类型的SOAP客户端产生了影响。所以我们上面的例子看起来更像是:

[Serializable()]
public List<StepInstance> StepInstances { get { return mStepInstances; } { set { mStepInstances = value; } }

private List<StepInstance> mStepInstances = new List<StepInstance>;

...

[Serializable()]
public class StepInstance {
    private string msPartnerKey = "";
    private string msObjectID = "";

    public string PartnerKey { get { return msPartnerKey; } set { msPartnerKey = value; } }
    public string ObjectID { get { return msObjectID; } set { msObjectID = value; } }
}