简体   繁体   English

WPF应用程序托管WCF访问冲突

[英]WPF Application hosting WCF Access Violation

I've been reading up (apparently not that well) on hosting a small WCF service inside a WPF application. 我一直在阅读(显然不是很好)有关在WPF应用程序中托管小型WCF服务的信息。 It's a suite of tools that has a master tray application that acts as the information distribution point between them all. 这是一套工具,具有一个主任务栏应用程序,充当它们之间的信息分发点。

When I try and create the new service host I get an access violation, simplified code as follows: 尝试创建新的服务主机时,出现访问冲突,简化代码如下:

    [ServiceContract]
public interface IMyService
{
    [WebInvoke(Method = "GET",
       BodyStyle = WebMessageBodyStyle.WrappedRequest,
       RequestFormat = WebMessageFormat.Json,
       ResponseFormat = WebMessageFormat.Json,
       UriTemplate = "/SampleMethod")] 
    [OperationContract]
    void addSearch(object data);
}

MyService.cs MyService.cs

    public class MyService: IMyService
{
    // Instantiate the API wrapper class.
    private MainWindow.api myApi = new MainWindow.api();

    public void addSearch(object data)
    {
        myApi.addSearch(data);
    }

}

Then in the onload event of my main WPF Window error is: *A first chance exception of type 'System.ArgumentException' occurred in System.ServiceModel.dll 然后在我的主要WPF窗口的onload事件中,错误是:* System.ServiceModel.dll中发生了类型为'System.ArgumentException'的第一次机会异常

The program '[13672] MyApplication.vshost.exe' has exited with code -1073741819 (0xc0000005) 'Access violation'.* 程序“ [13672] MyApplication.vshost.exe”已退出,代码为-1073741819(0xc0000005)“访问冲突”。*

        Uri httpUrl = new Uri("http://localhost:8090/MyService/Test");
        //Create ServiceHost
        // **ERROR HERE
        ServiceHost host = new ServiceHost(typeof(MyService), httpUrl);
        //Add a service endpoint
        host.AddServiceEndpoint(typeof(IMyService), new WSHttpBinding(), "");
        //Start the Service
        host.Open();

App.manifest App.manifest

<security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
      </requestedPrivileges>
  <applicationRequestMinimum>
    <PermissionSet Unrestricted="true" ID="Custom" SameSite="site" />
    <defaultAssemblyRequest permissionSetReference="Custom" />
  </applicationRequestMinimum>
</security>

I've been reading tutorials on this so it's probable I have misunderstood something so any pointers are very much appreciated. 我一直在阅读有关此内容的教程,所以很可能我误解了一些东西,因此非常感谢任何指针。

The error 'Access Violation' actually occurs for any syntax error in a WPF application hosting a WCF service. 实际上,托管WCF服务的WPF应用程序中的任何语法错误都会发生“访问冲突”错误。

System.ArgumentException is the important one, obviously indicating I had some of the arguments wrong. System.ArgumentException是重要的,显然表明我有一些错误的参数。 I'm just testing a working example and will post back with code that works! 我正在测试一个有效的示例,并将使用有效的代码发回!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM