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>
我已经对这个阅读教程,所以它可能我误解了一些东西,所以任何指针都非常感谢。