[英]An exception of type 'System.InvalidOperationException' occurred in System.ServiceModel.dll but was not handled in user code
I have two projects called A and B . 我有两个名为A和B的项目。 Now, i have one service class in B project and inside the service class, i have one endpoint like below:
现在,我在B项目中有一个服务类,在服务类中有一个端点,如下所示:
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class ReportAPIService
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function HelloWorld() As String
Return "Hello World"
End Function
End Class
Now, i want to call this endpoint from another WebAPI project and which is A . 现在,我想从另一个WebAPI项目(即A)中调用此终结点。 So, to achieve this, at first i ran the B project locally in my environment.
因此,要实现这一目标,首先我在自己的环境中本地运行了B项目。 Then, added a service reference of the ReportAPIService in my A project and it has been added successfully.
然后,在我的A项目中添加了ReportAPIService的服务引用,并且已成功添加。 I gave the service address as below:
我给的服务地址如下:
http://localhost:4043/ReportAPIService/ReportAPIService.asmx
http:// localhost:4043 / ReportAPIService / ReportAPIService.asmx
Then, i added below code to call the endpoint in project A . 然后,我添加了以下代码以调用项目A中的终结点。
ReportAPIServiceSoapClient soapClient = new ReportAPIServiceSoapClient();
return soapClient.HelloWorld();
But, it gives me the below error when trying to initialize ReportAPIServiceSoapClient() : 但是,当尝试初始化ReportAPIServiceSoapClient()时,它给了我以下错误:
An exception of type 'System.InvalidOperationException' occurred in System.ServiceModel.dll but was not handled in user code
System.ServiceModel.dll中发生类型'System.InvalidOperationException'的异常,但未在用户代码中处理
Additional information: Could not find default endpoint element that references contract 'ReportService.ReportAPIServiceSoap' in the ServiceModel client configuration section.
附加信息:在ServiceModel客户端配置部分中找不到引用合同'ReportService.ReportAPIServiceSoap'的默认终结点元素。 This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
这可能是因为找不到您的应用程序的配置文件,或者是因为在客户端元素中找不到与该协定匹配的端点元素。
What should i have to add in the client configuration section? 我必须在“客户端配置”部分中添加什么?
Then, i tried with HTTPClient
like below: 然后,我尝试使用
HTTPClient
如下所示:
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://localhost:4043/ReportAPIService/ReportAPIService.asmx/");
client.DefaultRequestHeaders.Accept.Clear();
HttpResponseMessage response = await client.GetAsync("HelloWorld");
return await response.Content.ReadAsStringAsync();
But, stuck at the GetAsync
method. 但是,被卡在
GetAsync
方法上。 No response from the server. 服务器无响应。
web.config in WCF service: WCF服务中的web.config:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="ReportAPIServiceSoap" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:4043/ReportAPIService/ReportAPIService.asmx"
binding="basicHttpBinding" bindingConfiguration="ReportAPIServiceSoap"
contract="ReportService.ReportAPIServiceSoap" name="ReportAPIServiceSoap" />
</client>
</system.serviceModel>
Is there any other way to call a endpoint of a project from an another project in ASP.NET? 还有其他方法可以从ASP.NET中的另一个项目中调用一个项目的终结点吗?
Your configuration looks wrong to me. 您的配置对我来说似乎是错误的。 A simplified one looks like below.
简化的如下所示。 See Documentation for more information
有关更多信息,请参见文档
<system.serviceModel>
<services>
<service name="<Provide Fully qualified service name>">
<endpoint address="http://localhost:4043/ReportAPIService/ReportAPIService.asmx"
binding="basicHttpBinding" contract="ReportService.ReportAPIServiceSoap"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.