2012-03-24 126 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