我是WCF的初学者,但试图改善我的经验.在第一步,我遇到了问题.我创建了最简单的WCF服务.代码清单:(所有代码都在一个文件中)
using System;
using System.ServiceModel;
namespace EssentialWCF
{
[ServiceContract]
public interface IStockService
{
[OperationContract]
double GetPrice(string ticker);
}
public class StockService : IStockService
{
public double GetPrice(string ticker)
{
return 94.85;
}
}
class Service
{
static void Main(string[] args)
{
ServiceHost serviceHost = new ServiceHost(typeof(StockService),
new Uri("http://localhost:8000/HelloWCF"));
serviceHost.AddServiceEndpoint(typeof(IStockService), new BasicHttpBinding());
serviceHost.Open();
Console.WriteLine("To continue press ENTER");
serviceHost.Close();
}
}
}
Run Code Online (Sandbox Code Playgroud)
那将是通过控制台给我一个号码的服务.但调试给我例外:(而不是数字:))
HTTP无法注册URL http:// +:8000/HelloWCF /.您的进程没有此命名空间的访问权限(有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkId=70353).
你有没有遇到过同样的情况?我很乐意看到每一条建议.
我想在窗口服务中托管wcf.我以前做过几次没有任何问题.这次安装服务并单击启动后,我在EventViewer中收到以下错误.
Service cannot be started. System.ServiceModel.AddressAccessDeniedException: HTTP could not register URL http://+:.../.../. Your process does not have access rights to this namespace (see http://go.microsoft.com/fwlink/?LinkId=70353 for details).
当我在ConsoleApplication上托管相同的服务,相同的地址时 - 好的.
有没有人有想法?
我有一个复杂的基于WCF服务的解决方案在我的PC上工作,但由于安装Windows 8.1时出现问题,我不得不'刷新'我的电脑.现在我重新安装了Visual Studio 2012,我的项目不再正常运行.
当我调试单元测试时,wcfservicehost显示错误:
Please try changing the HTTP port to 8733 or running as Administrator.
System.ServiceModel.AddressAccessDeniedException: HTTP could not register URL http://+:8732/Design_Time_Addresses/MyWCFService/Name/. Your process does not have access rights to this namespace (see http://go.microsoft.com/fwlink/?LinkId=70353 for details). ---> System.Net.HttpListenerException: Access is denied
Run Code Online (Sandbox Code Playgroud)
显然,通常的解决方案是以管理员身份运行Visual Studio(可能因为它会在某处覆盖某些内容)但是我无法执行此操作,因为我需要在网络驱动器上引用DLL并且当您使用时无法访问网络驱动器以管理员身份运行.
我假设有一个配置文件或注册表项确定运行时Visual Studio或WCF服务主机使用哪个端口,并且我以前的Windows安装中有一个剩余的条目.
要将端口更改为8733,需要编辑每个服务,重新引用它们,然后重建解决方案并希望它能够正常工作.
有没有办法设置或强制WCF服务主机使用的端口?
我正在测试我的WCF服务,但我需要伪造行为,因为我的服务是使用自定义工厂引导的.这是我为测试编写的代码:
var channelFactory = new ChannelFactory<IDomainWriteService>(
new CustomBinding(
new BinaryMessageEncodingBindingElement(),
new HttpTransportBindingElement()),
new EndpointAddress(new Uri("local")));
var service = channelFactory.CreateChannel();
Run Code Online (Sandbox Code Playgroud)
我有一个测试初始化,它正在创建一个新的ServiceHost:
internal static void StartService()
{
Instance = new ServiceHost(typeof (DomainWriteService));
Instance.Open();
}
Run Code Online (Sandbox Code Playgroud)
我通过以下方式在MsTest项目中配置了一个假端点:
<service name="xxx.DomainWriteService">
<endpoint binding="basicHttpBinding" bindingConfiguration=""
name="local" bindingName="http" contract="xxx.IDomainWriteService" />
<host>
<baseAddresses>
<add baseAddress="http://xxx/service" />
</baseAddresses>
</host>
</service>
Run Code Online (Sandbox Code Playgroud)
但是当我运行我的测试时,我得到了这个运行时错误:
Class Initialization method xxx.ClassInitialize threw exception. System.ServiceModel.AddressAccessDeniedException:
System.ServiceModel.AddressAccessDeniedException:
HTTP could not register URL **http://+:80/service/**.
Your process does not have access rights to this namespace
(see http://go.microsoft.com/fwlink/?LinkId=70353 for details). ---> …Run Code Online (Sandbox Code Playgroud)