本文介绍了控制台应用程序中的WCF服务抛出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

控制台应用程序中托管的BasicHttp和NetTcp绑定

我有下面的web.config文件

I have the below web.config file

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="HelloService.HelloService"  behaviorConfiguration="mexBehaviour">
        <endpoint address="HelloService" binding="basicHttpBinding" contract="HelloService.IHelloService"></endpoint>
        <endpoint address="HelloService" binding="netTcpBinding" contract="HelloService.IHelloService"></endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:59084/"/>
            <add baseAddress="net.tcp://localhost:59076/"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="mexBehaviour">
          <serviceMetadata httpGetEnabled="True"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

界面

namespace HelloService
{
    [ServiceContract]
    public interface IHelloService
    {
        [OperationContract]
        String GetMessage(String Name);
    }
}

扩展接口的类

 using System.ServiceModel;
    namespace HelloService
    {
        public class HelloService : IHelloService
        {
            public string GetMessage(string Name)
            {
                return "Hello " + Name;
            }
        }
    }

和用于托管的控制台应用代码

and Console App code for hosting

using System.ServiceModel;

namespace HelloServiceHost
{
    class Program
    {
        static void Main()
        {
            using(ServiceHost host  = new ServiceHost(typeof(HelloService.HelloService)))
            {
                host.Open();
                Console.WriteLine("Host Started");
                Console.ReadLine();
            }
        }
    }
}

当我尝试运行控制台应用程序时出现错误消息

I am getting below error when i try to run the Console app

HTTP could not register URL http://+:8080/. Your process does not have
access rights to this namespace (see
http://go.microsoft.com/fwlink/?LinkId=70353 for details).

  • 我尝试使用其他端口号(例如53895),认为端口8080可能已被占用.没运气!!
  • 当我浏览此错误时,由于我的原因,我开始知道此问题帐户是非管理员.现在我的疑问是WCFTest Client是否也执行了在我自己的帐户下.它怎么能运行类似的代码而我不能?

    • I tried other port number like 53895, thinking port 8080 might be pre occupied. No Luck!!
    • When i browsed for this error, i came to know this problem due to myaccount being non admin. Now my doubt is WCFTest Client also execuedunder my account itself. How can it run the similar code and i can't?

      此外,任何建议进行这项工作的建议都会被采纳.也许再次与Webconfig有关?

      Also, any suggestions to make this work would be appriciated. May besomething to do with Webconfig again??

      谢谢您的帮助!

      推荐答案

      您的代码看起来还不错.我试过了,它起作用了.在此处尝试解决方案: HTTP无法注册URL http://+:8000/HelloWCF/.您的进程没有对此命名空间的访问权限

      Your code looks alright. I tried it and it works.Try the solution here: HTTP could not register URL http://+:8000/HelloWCF/. Your process does not have access rights to this namespace

      它基本上告诉您关闭Visual Studio IDE并通过右键单击以管理员身份运行"将其打开

      It basically tells you to close your Visual Studio IDE and open it by doing a right-click "Run as administrator"

      这篇关于控制台应用程序中的WCF服务抛出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 05:15