【问题标题】:System.ServiceModel.EndpointNotFoundException: There was no endpoint listeningSystem.ServiceModel.EndpointNotFoundException:没有端点监听
【发布时间】:2019-11-19 08:51:46
【问题描述】:

我在 Visual Studio 中有一个新的 WPF 项目。我想连接到这个网址:“http://www.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL”。

我已提供服务参考。

当我运行它时,我得到了这个错误(我已将文本翻译成英文):

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

该网址可在 Google Chrome 中与 Widzler 完美配合。

代码:

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>

【问题讨论】:

    标签: c# wcf service-reference


    【解决方案1】:

    我发现问题在于我的 Visual Studio 解决方案位于网络驱动器上(Windows 将其称为“K”)。当我将解决方案移至 C 盘时,它运行良好。

    感谢您的宝贵时间!

    【讨论】:

      【解决方案2】:

      在我创建一个新控制台并测试您提供的 URL 后,它运行良好。
      调用服务的代码段和你上面贴的一样,包括Appconfig文件中的服务端点。
      结果。

      两个端点都能正常工作,我什至用自定义绑定测试端点。

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

      因此,我怀疑您的本地网络连接有问题。
      建议你关闭本地防火墙、杀毒软件、本地Hosts文件,用Ping命令查明问题所在,查看该机浏览器是否可以访问该URL。
      如果问题仍然存在,请随时告诉我。

      【讨论】:

      • 在我的本地 PC 上的 Google Chrome 中使用 Widzler 可以正常工作。 Visual Studio 也在我的本地 PC 上。在我向我的网络/防火墙/防病毒同事寻求帮助之前,您对该信息有任何意见吗?
      • 你的意思是可以直接在浏览器中访问WSDL文件吗?这至少表明网络连接几乎没有问题。此外,我们可以尝试通过添加服务引用在另一个控制台应用程序中调用该服务。
      • 是的,如果我在 Chrome 中输入“oorsprong.org/websamples.countryinfo/…”,那么它可以正常工作。我可以使用 Widzler 调用函数并获得回复。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-05
      • 2014-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多