WCF 在VS中,添加服務引用,地址輸入http://ip/Service.svc,點擊前往,提示錯誤,內容如下:


 

WCF的service端的webconfig如下:

<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
    <services>
      <service behaviorConfiguration="ServiceBehavior"
               name="WcfServiceLibrary1.Service1">
        <endpoint binding="wsHttpBinding"
                  bindingConfiguration=""
                  contract="WcfServiceLibrary1.IService1"/>
      </service>
    </services>
  </system.serviceModel>
</configuration>

WCF 在VS中,添加服務引用,地址輸入http://ip/Service.svc,點擊前往,提示錯誤,內容如下:

下載“http://127.0.0.1:7293/WCFServerRefWCFLib.svc”時出錯。
請求因 HTTP 狀態 404 失敗: Not Found。
元數據包含無法解析的引用:“http://127.0.0.1:7293/WCFServerRefWCFLib.svc”。
沒有終結點在偵聽可以接受消息的 http://127.0.0.1:7293/WCFServerRefWCFLib.svc。這通常是由於不正確的地址或者 SOAP 操作導致的。如果存在此情況,請參見 InnerException 以了解詳細信息。
遠程服務器返回錯誤: (404) 未找到。
如果該服務已在當前解決方案中定義,請嘗試生成該解決方案,然后再次添加服務引用。

  

解決方法是:

在<system.serviceModel>節點中添加:

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>

最后的配置是:

 

<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>     <services>
      <service behaviorConfiguration="ServiceBehavior"
               name="WcfServiceLibrary1.Service1">
        <endpoint binding="wsHttpBinding"
                  bindingConfiguration=""
                  contract="WcfServiceLibrary1.IService1"/>
      </service>
    </services>
  </system.serviceModel>
</configuration>

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM