2012-04-15 64 views
1

我得到这个HTTP错误404.0 - 找不到试图本地

HTTP错误404.0访问WCF时 - 找不到 您正在寻找已被删除的资源,有其名称更改,或者暂时不可用。

当试图从我的浏览器访问服务。这是我的配置。

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 

     <services> 
      <!-- Note: the service name must match the configuration name for the service implementation. --> 
      <service name="WcfServiceLibrary.Service1" behaviorConfiguration="MyServiceTypeBehaviors" > 
       <!-- Add the following endpoint. --> 
       <!-- Note: your service must have an http base address to add this endpoint. --> 
       <endpoint contract="WcfServiceLibrary.Service1" binding="basicHttpBinding" address="http://localhost/service1" /> 
       <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="http://localhost/service1/mex" /> 
      </service> 
     </services> 

     <behaviors> 
      <serviceBehaviors> 
       <behavior name="MyServiceTypeBehaviors" > 
        <!-- Add the following element to your service behavior configuration. --> 
        <serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost/service1" /> 
       </behavior> 
      </serviceBehaviors> 
     </behaviors> 

    </system.serviceModel> 

</configuration> 

当我在Web浏览器中键入http://localhost/service1我得到了404,但如果我删除下面的app.config,只是simpley做到这一点在后面的代码

string serviceUrl = "http://localhost/service1"; 
Uri uri = new Uri(serviceUrl); 
host = new ServiceHost(typeof(Service1), uri); 
host.Open(); 

一切运作良好.. 。 有任何想法吗?看起来很简单。

+0

您是否试图在IIS或自托管中托管此项? – Martin 2012-04-15 17:46:05

+0

自己托管。我已经创建了一个Windows窗体应用程序 – stack 2012-04-15 18:16:12

+0

它由IIS自己托管仍然主持这个权利? – stack 2012-04-15 18:30:59

回答

3

我认为你是你的服务下丢失主机元素:

<service name="WcfServiceLibrary2.Service1"> 
    <host> 
     <baseAddresses> 
      <add baseAddress = "http://localhost/service1" /> 
     </baseAddresses> 
    </host> 
    <endpoint address ="" binding="wsHttpBinding" contract="WcfServiceLibrary2.IService1"> 
     <identity> 
      <dns value="localhost"/> 
     </identity> 
    </endpoint> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
</service> 

服务主机不需要URL即可。

static void Main(string[] args) 
    { 
     var host = new ServiceHost(typeof(Service1)); 
     host.Open(); 

     Console.WriteLine("Host running"); 
     Console.ReadLine(); 
    } 
+0

谢谢你的工作。但作为额外的原因,我为什么不能在浏览器中以这种方式查看mex http:// localhost/service1/mex? – stack 2012-04-16 11:26:58

+0

只是好奇,为什么这是低票? – 2012-04-21 06:56:02

0

您可以显示在浏览器http://localhost/service1?Wsdl但MEX只添加服务引用或WCFTestClient工程(C:\ Program Files文件(x86)的\微软的Visual Studio 10.0 \ Common7 \ IDE),因为你会得到HTTP错误请求错误来自浏览器发出HTTP GET请求,其中消息的内容位于HTTP标头中,并且主体为空。

这正是WCF mexHttpBinding所抱怨的。

+0

感谢您的信息... – stack 2012-04-17 21:07:45

相关问题