2012-04-15 47 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

相關問題