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