2015-02-17 82 views
1

我一直在閱讀(顯然不是很好)在WPF應用程序內託管一個小WCF服務。這是一套工具,它有一個主托盤應用程序,充當它們之間的信息分發點。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] MyApplic ation.vshost.exe」已退出,代碼爲-1073741819(0000005) '訪問衝突'。*

 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> 

我已經對這個閱讀教程,所以它可能我誤解了一些東西,所以任何指針都非常感謝。

回答

0

對於承載WCF服務的WPF應用程序中的任何語法錯誤,實際發生錯誤「訪問衝突」。

System.ArgumentException是重要的,顯然表明我有一些參數錯誤。我只是測試一個工作示例,並將回傳可用的代碼!