[英]WCF Service Reference not working?
我已經創建了一個RESTful WCF服務(感謝StackOverflow)。 我創建了一個測試客戶端,它是一個帶有5個文本框和一個提交按鈕的簡單.aspx頁面。 當我在文本框中輸入數據並單擊Submit按鈕時,它將把數據提交到WCF服務。
我的WCF服務在Visual Studio開發服務器下運行,並且運行良好,我能夠將數據成功發送到WCF服務。 今天,我在本地IIS上部署了此WCF服務。 當我嘗試在客戶端應用程序(.aspx頁)中引用服務URL時,出現此錯誤。
“元數據包含無法解析的引用。客戶端和服務綁定可能不匹配。由於內容類型'application / soap + xml; charset = utf-8'不是預期的類型'text / xml,因此無法處理消息。 ”
知道可能是什么問題嗎? 這是我的web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="RESTService1">
<endpoint address="http://localhost:420/WCFRESTService100/RESTService1.svc" binding="webHttpBinding" name="MainHttpPoint" contract="RESTService1" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:420/WCFRESTService100/RESTService1.svc" />
</baseAddresses>
</host>
</service>
</services>
<!--<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>-->
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
</configuration>
我認為問題在於您根本沒有為REST服務添加服務引用。 REST服務沒有任何可用的元數據,因為沒有用於描述它們的標准元數據格式。
能夠添加服務引用的唯一原因是因為您留在服務上,該服務公開了它的SOAP定義。 因此,如果粘貼您的客戶端配置,我確定該端點存在一個SOAP端點(wsHttpBinding或basicHttpBinding),因此您在進行調用時會收到有關mime類型不匹配的錯誤的原因。
如果要使用WCF從客戶端調用REST服務,則需要在客戶端和服務器之間共享合同定義,或者在客戶端完全復制它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.