简体   繁体   English

System.ServiceModel.EndpointNotFoundException:没有端点监听

[英]System.ServiceModel.EndpointNotFoundException: There was no endpoint listening

I have a new WPF project in Visual Studio.我在 Visual Studio 中有一个新的 WPF 项目。 I want to connect to this url: " http://www.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL ".我想连接到这个 url:“ http://www.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL ”。

I have made a Service Reference.我已经做了一个服务参考。

When I run it, I get this error (I have translated the text to English):当我运行它时,我收到此错误(我已将文本翻译成英文):

System.ServiceModel.EndpointNotFoundException
  HResult=0x80131501
  Message=There was no endpoint listening at http://www.oorsprong.org/websamples.countryinfo/CountryInfoService.wso, that can accept the message. This is often because of a wrong address or SOAP-action. Find more information at InnerException.
  Source=mscorlib
  StackTrace:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at ContactCountry.CountryConverter.CountryInfoServiceSoapType.CapitalCity(CapitalCityRequest request)
   at ContactCountry.CountryConverter.CountryInfoServiceSoapTypeClient.ContactCountry.CountryConverter.CountryInfoServiceSoapType.CapitalCity(CapitalCityRequest request) in K:\Dokumenter\Programmer\ContactCountry\ContactCountry\Connected Services\CountryConverter\Reference.cs:line 2235
   at ContactCountry.CountryConverter.CountryInfoServiceSoapTypeClient.CapitalCity(String sCountryISOCode) in K:\Dokumenter\Programmer\ContactCountry\ContactCountry\Connected Services\CountryConverter\Reference.cs:line 2242
   at ContactCountry.MainWindow..ctor() in K:\Dokumenter\Programmer\ContactCountry\ContactCountry\MainWindow.xaml.cs:line 29

Inner Exception 1:
WebException: The underlying connection was closed: Cannot connect to remote server.

Inner Exception 2:
SocketException: There was given an illegal argument

The url works fine with Widzler in Google Chrome. url 与 Google Chrome 中的 Widzler 配合得很好。

Code:代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ContactCountry
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            CountryConverter.CountryInfoServiceSoapTypeClient client = new CountryConverter.CountryInfoServiceSoapTypeClient("CountryInfoServiceSoap");

            myTextBox.Text = client.CapitalCity("US");
        }
    }
}

app.config:应用程序配置:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
    </startup>

  <system.net>
    <defaultProxy enabled="false" useDefaultCredentials="false">
    </defaultProxy>
  </system.net>

  <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="CountryInfoServiceSoapBinding" />
            </basicHttpBinding>
            <customBinding>
                <binding name="CountryInfoServiceSoapBinding12">
                    <textMessageEncoding messageVersion="Soap12" />
                    <httpTransport />
                </binding>
            </customBinding>
        </bindings>
        <client>
            <endpoint address="http://www.oorsprong.org/websamples.countryinfo/CountryInfoService.wso"
                binding="basicHttpBinding" bindingConfiguration="CountryInfoServiceSoapBinding"
                contract="CountryConverter.CountryInfoServiceSoapType" name="CountryInfoServiceSoap" />
            <endpoint address="http://www.oorsprong.org/websamples.countryinfo/CountryInfoService.wso"
                binding="customBinding" bindingConfiguration="CountryInfoServiceSoapBinding12"
                contract="CountryConverter.CountryInfoServiceSoapType" name="CountryInfoServiceSoap12" />
        </client>
    </system.serviceModel>
</configuration>

I have found out that the problem is that my Visual Studio solution is on a network drive (that Windows knows as "K").我发现问题在于我的 Visual Studio 解决方案位于网络驱动器上(Windows 称为“K”)。 When I moved the solution to C drive, it works perfectly.当我将解决方案移至 C 驱动器时,它运行良好。

Thanks for your time!谢谢你的时间!

You should pass binding name into constructor.您应该将绑定名称传递给构造函数。 Try this尝试这个

var client = new CountryConverter.CountryInfoServiceSoapTypeClient("CountryInfoServiceSoapBinding");

After I create a new console and test the URL you provided, it works well.在我创建一个新控制台并测试您提供的 URL 后,它运行良好。
The code segments of calling the service are the same as what you have posted above, including the service endpoint in the Appconfig file.调用服务的代码段和你上面贴的一样,包括Appconfig文件中的服务端点。
Result.结果。
在此处输入图像描述
Both endpoints work properly, I even test the endpoint with custom binding.两个端点都能正常工作,我什至使用自定义绑定测试端点。

ServiceReference1.CountryInfoServiceSoapTypeClient client = new
ServiceReference1.CountryInfoServiceSoapTypeClient("CountryInfoServiceSoap12");
MyLabel.Content = client.CapitalCity("US");

Therefore, I suspect there is something wrong with your local network connectivity.因此,我怀疑您的本地网络连接有问题。
I suggest you close the local firewall, anti-virus software, local Hosts file, pinpoint the issue by using the Ping command, check whether we can access the URL in the browser in that machine.建议你关闭本地防火墙、杀毒软件、本地Hosts文件,使用Ping命令查明问题所在,查看该机浏览器能否访问URL。
Feel free to let me know if the problem still exists.如果问题仍然存在,请随时告诉我。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法引用 System.ServiceModel.EndpointNotFoundException - Can't reference System.ServiceModel.EndpointNotFoundException 在IIS上使用WCF服务时引发System.ServiceModel.EndpointNotFoundException - System.ServiceModel.EndpointNotFoundException thrown when consuming wcf service on IIS 捕获“&#39;System.ServiceModel.EndpointNotFoundException”异步Web服务调用期间发生异常 - Catching " 'System.ServiceModel.EndpointNotFoundException' Exception happening during asynchronous web service call System.ServiceModel.EndpointNotFoundException:无法连接到net.tcp://127.0.0.1/TestService - System.ServiceModel.EndpointNotFoundException: Could not connect to net.tcp://127.0.0.1/TestService 正在获取EndpointNotFoundException:WCF中没有正在积极监听的频道 - Getting EndpointNotFoundException: There was no channel actively listening in WCF 没有端点监听 - No Endpoint listening 没有端点监听 - There was no endpoint listening System.ServiceModel.CommunicationException:'服务端点未能侦听 URI'xxx',因为访问被拒绝 - System.ServiceModel.CommunicationException: 'The service endpoint failed to listen on the URI 'xxx' because access was denied 异常:System.ServiceModel.AddressAlreadyInUseException:IP 端点 0.0.0.0:808 上已经有一个侦听器 - Exception: System.ServiceModel.AddressAlreadyInUseException: There is already a listener on IP endpoint 0.0.0.0:808 使用Microsoft.Web.Administration.ServerManager修改web.config system.ServiceModel / client / endpoint - Modify web.config system.ServiceModel/client/endpoint with Microsoft.Web.Administration.ServerManager
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM