将SOAP响应解析为ListBox错误

时间:2013-09-30 11:36:12

标签: c# xaml windows-phone-7 soap listbox

我正在使用SOAP服务制作Windows Phone应用程序。我想将XML响应解析为ListBox,但我有多个错误。

这是我的所有代码和日志:

Verkopen.xaml

(...)    
<ListBox Height="601" HorizontalAlignment="Left" Name="listBox1" VerticalAlignment="Top" Width="460" DataContext="{Binding}" Foreground="Black" FontSize="32" Grid.Row="0" Grid.RowSpan="1">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Vertical">
                                <TextBlock Text="Sample" ></TextBlock>
                                <TextBlock Text="{Binding omschr}"></TextBlock>
                                <TextBlock Text="{Binding totalen}" ></TextBlock>
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
(...)

Verkopen.xaml.cs

    (...)
     class XMLInfo
        {
            public string omschr { get; set; }
            public string totalen { get; set; }
        }
    (...)
private void ophalencompleet(object sender, SalesService.retSalesCompletedEventArgs e)
        {
     string XMLResponse = e.Result;
                var XResult = XElement.Parse(XMLResponse);

                var result = XResult.Descendants("Table").Select(t => new XMLInfo
        {
            omschr = t.Descendants("omschr").First().Value,
            totalen = t.Descendants("exclusief").First().Value,
        });

                foreach (var res in result)
                {
                    string omschr = res.omschr; // here i am able get the response
                    Debug.WriteLine("Wat in de tabel zou moeten: " + omschr);
                    string totalen = res.totalen;
                }

                listBox1.ItemsSource = result;
    (...)

SOAP响应

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
  <Table>
    <expnr>672 </expnr>
    <artnr>GX-05           </artnr>
    <omschr>Glaswerk OP=OP                </omschr>
    <datum>2013-09-30T00:00:00+02:00</datum>
    <aantal>1</aantal>
    <exclusief>2.44</exclusief>
    <inclusief>2.95</inclusief>
    <loca_id>0490</loca_id>
  </Table>
  <Table>
    <expnr>672 </expnr>
    <artnr>LZ03-0008       </artnr>
    <omschr>Pot RH 50x15x24,5 zwart       </omschr>
    <datum>2013-09-30T00:00:00+02:00</datum>
    <aantal>1</aantal>
    <exclusief>20.62</exclusief>
    <inclusief>24.95</inclusief>
    <loca_id>0490</loca_id>
  </Table>
</NewDataSet>

错误:

A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
System.Windows.Data Error: Cannot get 'omschr' value (type 'System.String') from 'CtrlBase.XMLInfo' (type 'CtrlBase.XMLInfo'). BindingExpression: Path='omschr' DataItem='CtrlBase.XMLInfo' (HashCode=241995340); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'Text' (type 'System.String').. System.MethodAccessException: Attempt to access the method failed: CtrlBase.XMLInfo.get_omschr()
   at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
   at System.Reflection.RuntimePropertyInfo.InternalGetValue(PropertyInfo thisProperty, Object obj, Object[] inA first chance exception of type 'System.MethodAccessException' occurred in mscorlib.dll
A first chance exception of type 'System.MethodAccessException' occurred in mscorlib.dll
System.Windows.Data Error: Cannot get 'totalen' value (type 'System.String') from 'CtrlBase.XMLInfo' (type 'CtrlBase.XMLInfo'). BindingExpression: Path='totalen' DataItem='CtrlBase.XMLInfo' (HashCode=241995340); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'Text' (type 'System.String').. System.MethodAccessException: Attempt to access the method failed: CtrlBase.XMLInfo.get_totalen()
   at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
   at System.Reflection.RuntimePropertyInfo.InternalGetValue(PropertyInfo thisProperty, Object obj, Object[]A first chance exception of type 'System.MethodAccessException' occurred in mscorlib.dll
A first chance exception of type 'System.MethodAccessException' occurred in mscorlib.dll
System.Windows.Data Error: Cannot get 'omschr' value (type 'System.String') from 'CtrlBase.XMLInfo' (type 'CtrlBase.XMLInfo'). BindingExpression: Path='omschr' DataItem='CtrlBase.XMLInfo' (HashCode=241995360); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'Text' (type 'System.String').. System.MethodAccessException: Attempt to access the method failed: CtrlBase.XMLInfo.get_omschr()
   at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
   at System.Reflection.RuntimePropertyInfo.InternalGetValue(PropertyInfo thisProperty, Object obj, Object[] inA first chance exception of type 'System.MethodAccessException' occurred in mscorlib.dll
A first chance exception of type 'System.MethodAccessException' occurred in mscorlib.dll
System.Windows.Data Error: Cannot get 'totalen' value (type 'System.String') from 'CtrlBase.XMLInfo' (type 'CtrlBase.XMLInfo'). BindingExpression: Path='totalen' DataItem='CtrlBase.XMLInfo' (HashCode=241995360); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'Text' (type 'System.String').. System.MethodAccessException: Attempt to access the method failed: CtrlBase.XMLInfo.get_totalen()
   at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
   at System.Reflection.RuntimePropertyInfo.InternalGetValue(PropertyInfo thisProperty, Object obj, Object[]A first chance exception of type 'System.MethodAccessException' occurred in mscorlib.dll
A first chance exception of type 'System.MethodAccessException' occurred in mscorlib.dll
System.Windows.Data Error: Cannot get 'omschr' value (type 'System.String') from 'CtrlBase.XMLInfo' (type 'CtrlBase.XMLInfo'). BindingExpression: Path='omschr' DataItem='CtrlBase.XMLInfo' (HashCode=241995377); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'Text' (type 'System.String').. System.MethodAccessException: Attempt to access the method failed: CtrlBase.XMLInfo.get_omschr()
   at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
   at System.Reflection.RuntimePropertyInfo.InternalGetValue(PropertyInfo thisProperty, Object obj, Object[] inA first chance exception of type 'System.MethodAccessException' occurred in mscorlib.dll
A first chance exception of type 'System.MethodAccessException' occurred in mscorlib.dll
System.Windows.Data Error: Cannot get 'totalen' value (type 'System.String') from 'CtrlBase.XMLInfo' (type 'CtrlBase.XMLInfo'). BindingExpression: Path='totalen' DataItem='CtrlBase.XMLInfo' (HashCode=241995377); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'Text' (type 'System.String').. System.MethodAccessException: Attempt to access the method failed: CtrlBase.XMLInfo.get_totalen()
   at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
   at System.Reflection.RuntimePropertyInfo.InternalGetValue(PropertyInfo thisProperty, Object obj, Object[]The program '[267518466] UI Task: Managed' has exited with code 0 (0x0).

谁能帮我解决这个问题。我经常搜索Google,但没找到修复程序。 非常感谢!

1 个答案:

答案 0 :(得分:0)

我在博客文章中写过这个问题,请查看here

问题在于Windows Phone 7上的反射API。有趣的是,如果WP7应用程序在Windows Phone 8设备或模拟器上运行,上面的代码将起作用,因为在WP8上您可以访问私人/内部的东西。

如果遇到数据绑定问题,请检查类和/或属性是否公开。并尝试在调试模式下运行代码,并启用了break-on-thrown-exceptions。