![](/img/trans.png)
[英]Can't reference System.ServiceModel.EndpointNotFoundException
[英]System.ServiceModel.EndpointNotFoundException: There was no endpoint listening
我在 Visual Studio 中有一個新的 WPF 項目。 我想連接到這個 url:“ 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
url 與 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");
}
}
}
應用程序配置:
<?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>
我發現問題在於我的 Visual Studio 解決方案位於網絡驅動器上(Windows 稱為“K”)。 當我將解決方案移至 C 驅動器時,它運行良好。
謝謝你的時間!
您應該將綁定名稱傳遞給構造函數。 嘗試這個
var client = new CountryConverter.CountryInfoServiceSoapTypeClient("CountryInfoServiceSoapBinding");
在我創建一個新控制台並測試您提供的 URL 后,它運行良好。
調用服務的代碼段和你上面貼的一樣,包括Appconfig文件中的服務端點。
結果。
兩個端點都能正常工作,我什至使用自定義綁定測試端點。
ServiceReference1.CountryInfoServiceSoapTypeClient client = new
ServiceReference1.CountryInfoServiceSoapTypeClient("CountryInfoServiceSoap12");
MyLabel.Content = client.CapitalCity("US");
因此,我懷疑您的本地網絡連接有問題。
建議你關閉本地防火牆、殺毒軟件、本地Hosts文件,使用Ping命令查明問題所在,查看該機瀏覽器能否訪問URL。
如果問題仍然存在,請隨時告訴我。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.