2012-03-24 130 views
3

所以我之前的問題圍繞把wcf變成寧靜的服務convert a WCF Service, to a RESTful application?,我設法做一些幫助!沒有端點監聽wcf/rest

但我遇到了我的客戶一個新的問題:

There was no endpoint listening at http://localhost:26535/Service1.svc that could accept the message.
This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

現在RESTful服務運行,這可以從一個屏幕轉儲中可以看出:

enter image description here

而且我可以添加從url的值1像這樣:

enter image description here

但我卻似乎無法在Visual Studio中的另一個新的實例中運行它,我的客戶的app.config看起來是這樣的:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
     <bindings> 
      <customBinding> 
       <binding name="WebHttpBinding_IService1"> 
        <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" 
         messageVersion="Soap12" writeEncoding="utf-8"> 
         <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
          maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
        </textMessageEncoding> 
        <httpTransport></httpTransport> 
       </binding> 
      </customBinding> 
     </bindings> 
     <client> 
      <endpoint address="http://localhost:26535/Service1.svc" binding="customBinding" bindingConfiguration="WebHttpBinding_IService1" 
       contract="ServiceReference1.IService1" name="WebHttpBinding_IService1" /> 
     </client> 
    </system.serviceModel> 
</configuration> 

客戶端代碼:

namespace WindowsFormsApplication1 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     } 

     private void Form1_Load(object sender, EventArgs e) 
     { 

     } 

     public ServiceReference1.Service1Client testClient = new ServiceReference1.Service1Client(); 
     private void button1_Click(object sender, EventArgs e) 
     { 
      label1.Text = testClient.GetData(Convert.ToInt32(textBox1.Text)); 
     } 
    } 
} 

我看着前面的問題在SO上的這個區域:WCF - "There was no endpoint listening at..." error

但是它沒有提供解決方案嗎?我不熟悉在IIS上託管或不是這只是練習,所以讓它在調試(F5)上工作會更好!

+0

你的內部異常是什麼?這可能會對此有更多的瞭解。 – 2012-03-24 20:40:08

+0

做一個內部異常只是說遠程服務器返回一個錯誤:(404)未找到。 – 2012-03-24 20:56:33

回答

2

這可能實際上是由於對REST服務的更改。

嘗試刪除/從您的主機配置註釋掉這個

<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 

看來,REST沒有越過任何元數據(從而去除MEX)的

如果再重置服務引用,它應該正常工作......我相信。

此外,this article如果你能夠使用第三方可能證明是有用的

,那麼我會建議使用RestSharp。它使消費RESTful服務非常容易:)

或者你可以使用更新的WebAPI,可以使這些調用更直接嗎?問題是RESTful服務並不像SOAP調用那樣容易消耗

+0

如果我將我的客戶端中的綁定更改爲webhttpbinding我更新servicereference時出現錯誤,它說:服務引用的config由於以下問題而無法更新:'system.servicemodel/binding/webhttpbinding'中的阻止沒有一個名爲'webhttpbindig_Iservice1'的配置綁定,在'app.config行17'處是無效值綁定。 – 2012-03-24 21:49:00

+0

好吧,把customBinding放回去,但保留mex離開服務,看看會發生什麼:)...這篇文章也是使我相信這可能仍然是發送POST,當你正在尋找一個GET ... http://forums.asp.net/t/1695037.aspx/1你可以使用提琴手來看看發送的是什麼穿過電線? – 2012-03-24 21:50:12

+1

其實,最重要的是這一點。我會建議看看RestSharp。我不確定你是否可以使用它,但它使得使用REST服務變得非常簡單 – 2012-03-24 21:57:22