2011-08-31 132 views
1

我創建了一個WCF Web服務並在IIS(7)中創建了一個新站點。我爲http請求創建了一個新的端口(8002)。我可以瀏覽到該網站,並獲得典型的「你沒有權限查看此目錄...」,所以我知道該網站正在工作。但是,我在我的web.config(其中1.1.1.1被我的實際IP地址替換)中將我的端點地址設置爲「http://1.1.1.1:8002」。當我通過http://1.1.1.1:8002/service.svc瀏覽到服務時,我得到頁面無法找到錯誤。在站點的根文件夾中有一個service.svc。設置有什麼問題?WCF端點地址問題

這裏是有幫助的,如果(同樣,1.1.1.1被替換我的真實IP地址)的web.config文件:

<?xml version="1.0"?> 
    <configuration> 
     <system.web> 
     <compilation debug="true" targetFramework="4.0"/> 
     <customErrors mode="Off"/> 
     </system.web> 
     <system.serviceModel> 
     <bindings> 
      <basicHttpBinding> 
      <binding name="BasicBinding"> 
       <security mode="None"> 
       <transport clientCredentialType="None" /> 
       </security> 
      </binding> 
      </basicHttpBinding> 
     </bindings> 
     <services> 
      <service behaviorConfiguration="WcfService.ServiceBehavior" name="WcfService.Service"> 
      <endpoint address="http://1.1.1.1:8002" binding="basicHttpBinding" bindingConfiguration="BasicBinding" contract="WcfService.IService"> 
      </endpoint> 
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
      </service> 
     </services> 
     <behaviors> 
      <serviceBehaviors> 
      <behavior name="WcfService.ServiceBehavior"> 
       <serviceMetadata httpGetEnabled="true"/> 
       <serviceDebug includeExceptionDetailInFaults="true"/> 
      </behavior> 
      </serviceBehaviors> 
     </behaviors> 
     </system.serviceModel> 
     <system.webServer> 
     <modules runAllManagedModulesForAllRequests="true"/> 
     </system.webServer> 
    </configuration> 
+0

網站文件夾的名稱是什麼?你有沒有嘗試打http://1.1.1.1:8002/ /service.svc? – njebert

回答

4

在託管時,您不能在配置文件控制你的服務的地址IIS。您只能控制端點的相對地址 - 它相對於.svc文件。

因此,如果您在站點http://YourIP:8002中託管服務,則其地址爲http://YourIP:8002/Service.svc,並且端點中的地址元素與此地址有關。但我希望你不要直接在網站上提供服務。您在站點中有一些應用程序,並且應用程序的名稱是URL的一部分:http://YourIP:8002/YourApplicationName/Service.svc實際上,用於嵌套服務的每個文件夾都是URL的一部分。

+0

我試過你加入/Service.svc和相同結果的建議。瀏覽器表示無法找到頁面。 Service.svc位於站點的根目錄中,而不是子文件夾。我甚至可以瀏覽網站,並可以看到Service.svc。當我點擊它時,瀏覽器顯示無法找到網頁。 – user31673

+0

將端點/ @地址留空並再次嘗試 –

+0

工作正常。現在的問題是爲什麼地址需要空白?我總是看到列出的地址。你能解釋一下發生了什麼事嗎? – user31673