gpt4 book ai didi

c# - 没有端点监听 wcf/rest

转载 作者:行者123 更新时间:2023-11-30 17:13:21 25 4
gpt4 key购买 nike

所以我之前的问题围绕着将 wcf 变成一个 Restful 服务 convert a WCF Service, to a RESTful application? ,我设法在一些帮助下做到了!

但是我的客户遇到了一个新问题:

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) 上工作会很好!

最佳答案

这实际上可能是由于对 REST 服务的更改。

尝试从您的主机配置中删除/注释掉它

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

REST 似乎没有传递任何元数据(因此删除了 mex)

如果您随后重置服务引用,它应该可以正常工作...我相信。

此外,this article可能有用

如果你可以使用第三方,那么我建议使用 RestSharp .它使使用 RESTful 服务变得非常容易:)

或者您可以使用更新的 WebAPI 来使这些调用也更直接?问题是 RESTful 服务不像 SOAP 调用那样容易使用

关于c# - 没有端点监听 wcf/rest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9855134/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com