【问题标题】:WPF Application hosting WCF Access ViolationWPF 应用程序托管 WCF 访问冲突
【发布时间】:2015-04-18 17:38:36
【问题描述】:

我一直在阅读(显然不是那么好)在 WPF 应用程序中托管一个小型 WCF 服务。它是一套工具,其中包含一个主托盘应用程序,充当它们之间的信息分发点。

当我尝试创建新的服务主机时,我遇到了访问冲突,简化代码如下:

    [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

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

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

}

然后在我的主要 WPF 窗口错误的 onload 事件中是: *在 System.ServiceModel.dll 中发生了“System.ArgumentException”类型的第一次机会异常

程序“[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

<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>

我一直在阅读这方面的教程,所以很可能我误解了一些东西,所以非常感谢任何指针。

【问题讨论】:

    标签: c# wpf wcf


    【解决方案1】:

    托管 WCF 服务的 WPF 应用程序中的任何语法错误实际上都会发生“访问冲突”错误。

    System.ArgumentException 是重要的,显然表明我的一些论点是错误的。我只是在测试一个工作示例,并将返回有效的代码!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-02
      • 1970-01-01
      • 2017-01-20
      • 1970-01-01
      • 2012-03-16
      • 1970-01-01
      • 2016-04-04
      • 1970-01-01
      相关资源
      最近更新 更多