2015-10-05 85 views
0

我已經導入了一個wcf服務,它可以從本地主機訪問,但是當我使用我的公共IP地址時,我無法訪問它。WCF無法從網絡訪問

這是我的web.config文件的內容。

<?xml version="1.0"?> 
<configuration> 
    <system.web> 
     <compilation debug="true" 
        targetFramework="4.0" /> 
    </system.web> 
    <system.serviceModel> 
     <extensions> 
      <bindingExtensions> 
       <add name="clearUsernameBinding" 
        type="WebServices20.BindingExtenions.ClearUsernameCollectionElement, ClearUsernameBinding" /> 
      </bindingExtensions> 
      <!-- Add the inspector attribute as a behavior for displaying SOAP XML packets --> 
      <behaviorExtensions> 
       <add name="consoleOutputBehavior" 
        type="WcfService1.ConsoleOutputBehaviorExtensionElement, WcfService1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /> 
      </behaviorExtensions> 
     </extensions> 
     <bindings> 
      <clearUsernameBinding> 
       <binding name="myClearUsernameBinding" 
         messageVersion="Soap12" /> 
      </clearUsernameBinding> 
     </bindings> 
     <behaviors> 
      <!-- Add the inspector behavior --> 
      <endpointBehaviors> 
       <behavior name="inspectorBehavior"> 
        <consoleOutputBehavior /> 
       </behavior> 
      </endpointBehaviors> 
      <serviceBehaviors> 
       <behavior name="HelloWorldServiceBehavior"> 
        <serviceCredentials> 
         <userNameAuthentication userNamePasswordValidationMode="Custom" 
               customUserNamePasswordValidatorType="WcfService1.CustomUserNameValidator, WcfService1" /> 
        </serviceCredentials> 
        <serviceMetadata httpGetEnabled="true" /> 
        <serviceDebug includeExceptionDetailInFaults="false" /> 
       </behavior> 
      </serviceBehaviors> 
     </behaviors> 
     <services> 
      <service behaviorConfiguration="HelloWorldServiceBehavior" 
        name="WcfService1.HelloWorldService"> 
       <endpoint address="" 
          binding="clearUsernameBinding" 
          bindingConfiguration="myClearUsernameBinding" 
          contract="WcfService1.IHelloWorldService" /> 
      </service> 
     </services> 
    </system.serviceModel> 
    <system.webServer> 
     <modules runAllManagedModulesForAllRequests="true" /> 
    </system.webServer> 
</configuration> 

我有一個控制檯應用程序,它能夠與它通信,但只與本地主機通信。

這就是我能夠達到的目標。它在端口14946上運行,並將端口轉發到運行服務的計算機。它位於IIS上。

http://localhost:14946/HelloWorldService.svc?singleWsd

如果我使用:{} publicIP:14946/HelloWorldService.svc singleWsd 我得到一個500內部錯誤,這意味着它的配置問題,但我似乎無法找出問題是什麼?

編輯︰我現在收到此錯誤。

無法找到作爲ServiceHost指令中的Service屬性值提供的類型'WcfService1.HelloWorldService'。我現在可以通過網絡獲得它,但現在卻收到了這個錯誤。爲了解決以前的錯誤,我不得不:1)進入添加刪除功能2)展開MS的.NET Framework 3)扳動HTTP和非HTTP激活的WCF

感謝,

回答

0

如果你正確地主持它在IIS中你可以刪除終點港口和直接訪問它,像這樣:(add virtual application if necessary)

http://<public ip>/HelloWorldService.svc?singleWsd 

它是在你的本地主機的工作,因爲它是在IIS快遞在調試模式主辦,自動分配該端口。

+0

我已經嘗試過上述方法,但仍無法通過網絡訪問它。它必須是一個配置問題,但我似乎無法找到它 – RobertC

+0

你的IIS有虛擬目錄嗎?你是如何在IIS中託管你的服務的? – jtabuloc

+0

我只是右鍵點擊網站,並添加了一個網站。對於綁定,我只是將它綁定到我的機器專用IP,並且我已將端口轉發到此計算機。 – RobertC