WCF服务托管但部署时不起作用

时间:2014-12-18 18:17:00

标签: c# asp.net wcf

我是WCF的新手。这是对自托管WCF服务的尝试。我尝试使用basicHttpBinding创建我的第一个WCF服务,但它给我一个错误

  

'资源未找到404'。

我正在使用控制台应用程序托管我的WCF&通过网络应用程序使用它 托管中没有问题。当我浏览服务URL时,它运行很酷,甚至显示WSDL。 还向我显示了我创建服务的消息。 但是,当我尝试使用另一个VS2013(Admin Mode)实例通过Web应用程序使用该服务时,我得到一个例外说明:

  

“System.ServiceModel.ServerTooBusyException”类型的异常   发生在mscorlib.dll中但未在用户代码中处理

当我尝试使用代理类的对象调用服务方法时,会引发此异常。 这是我的控制台应用程序的App.config文件中的代码

<system.serviceModel>
<services>
  <service name="Hello_Service.HelloService" behaviorConfiguration="mexBehaviour">
    <endpoint address="" binding="basicHttpBinding" contract="Hello_Service.IHelloService"></endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8080/"/>
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="mexBehaviour">
      <serviceMetadata httpGetEnabled="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

这是控制台应用程序的Program.cs中的代码

using (ServiceHost host = new ServiceHost(typeof(Hello_Service.HelloService)))
        {
            host.Open();
            Console.WriteLine("Service started @ " + System.DateTime.Now.ToString());
            Console.ReadLine();
        }

这就是我在Web应用程序上使用WCF的方式

HelloService.HelloServiceClient client = new HelloService.HelloServiceClient("BasicHttpBinding_IHelloService");
        Label1.Text = client.GetMessage(TextBox1.Text);

这就是我在服务类中实现接口的方法

public class HelloService : IHelloService
{

    public string GetMessage(string name)
    {
        return "Hello" + name;
    }
}

我正在使用Visual Studio 2013&amp; Windows 8.1 我拒绝了我的防火墙设置&amp;我的Win Defender也是。但仍然没有成功。 可能是这个例外的可能原因以及如何摆脱它。 谢谢你的时间。请帮助。

0 个答案:

没有答案