Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 定义双工协定时引发Xaml解析异常_Wpf_Wcf_Exception_Xaml_Parsing - Fatal编程技术网

Wpf 定义双工协定时引发Xaml解析异常

Wpf 定义双工协定时引发Xaml解析异常,wpf,wcf,exception,xaml,parsing,Wpf,Wcf,Exception,Xaml,Parsing,我有一个包含WCF服务的WPF应用程序 Xaml代码非常简单: <Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Server" H

我有一个包含WCF服务的WPF应用程序

Xaml代码非常简单:

<Window    x:Class="WpfApplication1.Window1"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
           Title="Server" Height="308" Width="560" >
<Grid>
       <Grid Margin="2,2,0,0" Name="grid1">
           <RichTextBox Margin="14,29,12,39"    Name="richTextBox1" />
           <TextBox Height="24" Margin="16,0,80,9" Name="textBox1"    VerticalAlignment="Bottom">Enter your    text here</TextBox>
           <Button Height="24" HorizontalAlignment="Right"    Margin="0,0,12,9" Name="button1"    VerticalAlignment="Bottom"    Width="63">Send</Button>
           <Label Height="23" Margin="16,0,12,0" Name="label1"    VerticalAlignment="Top">Address:</Label>
       </Grid>
</Grid>
</Window>

在此处输入您的文本
发送
地址:
服务内容如下:

命名空间WpfApplication1 {

[ServiceContract(CallbackContract=typeof(IMyCallbackContract))]
公共接口IMyService
{
[运营合同(IsOneWay=true)]
void NewMessageToServer(字符串msg);
[运营合同(IsOneWay=true)]
bool ServerIsResponsible();
}
[服务合同]
公共接口IMyCallbackContract
{
[经营合同]
void NewMessageToClient(字符串msg);
[经营合同]
无效客户责任();
}
/// 
///Window1.xaml的交互逻辑
/// 
公共部分类Window1:Window
{
公共窗口1()
{
初始化组件();
ServiceMetadataBehavior行为=新建
ServiceMetadataBehavior();
//behavior.HttpGetEnabled=true;
//行为。
ServiceHost ServiceHost=new
服务主机(
类型(MyService),
新Uri(“net。tcp://localhost:8080/"));
serviceHost.Description.Behaviors.Add(行为);
serviceHost.AddServiceEndpoint(
类型(IMetadataExchange),
MetadataExchangeBindings.CreateMexTcpBinding(),
“墨西哥交易所”);
serviceHost.AddServiceEndpoint(
类型(IMyService),
新的NetTcpBinding(),
“ServiceEndpoint”);
Open();
MessageBox.Show(
“服务器已启动”);
//label1.Content=label1.Content+String.Format(“net。tcp://localhost:8080/");
}
}
公共类MyService:IMyService
{
public void NewMessageToServer(字符串msg)
{
}
公共布尔服务器负责()
{
返回true;
}
}
}

我在第1行遇到一个Xaml解析异常,可能是什么问题?
谢谢

您的Window1构造函数正在引发异常。令人困惑的是,WPF将这些异常包装在XamlParseException中,即使它们与XAML无关

要了解情况,请执行以下操作:

  • 中断异常并打开异常助手
  • 打开详细信息
  • 看看InnerException。这将是一个例外
  • 展开InnerException并查看其InnerException
  • 这个“内部异常”是在构造函数中抛出的异常。查看异常的类型和消息,然后从那里开始

  • 您的Window1构造函数正在引发异常。令人困惑的是,WPF将这些异常包装在XamlParseException中,即使它们与XAML无关

    要了解情况,请执行以下操作:

  • 中断异常并打开异常助手
  • 打开详细信息
  • 看看InnerException。这将是一个例外
  • 展开InnerException并查看其InnerException
  • 这个“内部异常”是在构造函数中抛出的异常。查看异常的类型和消息,然后从那里开始

  • 当构造函数中的某些内容甚至程序启动失败时,我经常会遇到XAML解析异常。尽管XAML是正确的,但运行时无法构造所有必要的对象来启动XAML并抛出此错误

    查看异常:是否有可能显示另一个错误的内部异常

    如果这没有帮助,请一步一步地调试。但如果没有任何进一步的帮助,这很难解决


    -sa

    当构造函数中的某些内容甚至程序启动失败时,我经常会遇到XAML解析异常。尽管XAML是正确的,但运行时无法构造所有必要的对象来启动XAML并抛出此错误

    查看异常:是否有可能显示另一个错误的内部异常

    如果这没有帮助,请一步一步地调试。但如果没有任何进一步的帮助,这很难解决


    -sa与我的回答重叠了。如果这有帮助,这应该被认为是答案。你写的关于XamlParseExceptions的优秀文章。只是和我的答案重叠了。如果这是有帮助的,这应该被认为是答案。你写的关于XamlParseExceptions的优秀文章。
    [ServiceContract(CallbackContract=typeof(IMyCallbackContract))]
    public interface IMyService
    {
        [OperationContract(IsOneWay = true)]
        void NewMessageToServer(string msg);
    
        [OperationContract(IsOneWay = true)]
        bool ServerIsResponsible();
    
    }
    
    
    
    [ServiceContract]
    public interface IMyCallbackContract
    {
        [OperationContract]
        void NewMessageToClient(string msg);
    
        [OperationContract]
        void ClientIsResponsible();
    
    }
    
    
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    
    
           public partial class Window1 : Window
         {
    
    
               public Window1()
             {
    
    
            InitializeComponent();
    
            ServiceMetadataBehavior behavior = new
            ServiceMetadataBehavior();
            //behavior.HttpGetEnabled = true;
    
            //behavior.
            ServiceHost serviceHost = new
            ServiceHost(
            typeof(MyService),
            new Uri("net.tcp://localhost:8080/"));
    
            serviceHost.Description.Behaviors.Add(behavior);
    
            serviceHost.AddServiceEndpoint(
                typeof(IMetadataExchange),
                MetadataExchangeBindings.CreateMexTcpBinding(),
                "mex");
    
            serviceHost.AddServiceEndpoint(
                typeof(IMyService),
                new NetTcpBinding(),
                "ServiceEndpoint");
    
                serviceHost.Open();
                MessageBox.Show(
                    "server is up");
    
           //  label1.Content = label1.Content + String.Format("   net.tcp://localhost:8080/");
            }
    
          }
    
           public class MyService : IMyService
           {
               public void NewMessageToServer(string msg)
               {
    
               }
    
               public bool ServerIsResponsible()
               {
                   return true;
               }
    
           }