简体   繁体   English

找不到名称为'Address:http://example.com:8123 / blmrg / test_ws / Service1.svc的终结点元素

[英]Could not find endpoint element with name 'Address:http://example.com:8123/blmrg/test_ws/Service1.svc

I have created a proxy class for a web service using svcutil.exe. 我已经使用svcutil.exe为Web服务创建了代理类。 I was trying to connect to webservice using below code. 我试图使用以下代码连接到Web服务。 Below exception occurred 发生以下异常

Could not find endpoint element with name 'Address: http://example.com:8123/blmrg/test_ws/Service1.svc ; 找不到名称为'Address: http : //example.com : 8123/blmrg/test_ws/Service1.svc的终结点元素; and contract 'IService1' in the ServiceModel client configuration section". This might be because no configuration file was found for your application. 并在ServiceModel客户端配置部分中与合同'IService1'签订合同。”这可能是因为未为您的应用程序找到配置文件。

When I tried to access that webservice url in browser, its working fine. 当我尝试在浏览器中访问该Web服务URL时,其工作正常。 Please let me know what went wrong in below code. 请让我知道以下代码出了什么问题。

My code: 我的代码:

ClientSection clientSection = ConfigurationManager.GetSection("system.serviceModel/client") as ClientSection;
ChannelEndpointElement endpoint = clientSection.Endpoints[0];
string endpointStr = string.Format("Address: {0}; Binding: {1}; Contract: {2}", endpoint.Address.ToString(), endpoint.Binding, endpoint.Contract);
Service1Client proxy = new Service1Client(endpointStr); // Getting exception here
CitizenType citizen = proxy.GetMan(562054);

App.config App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>  
<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IService1" />
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://example.com:8123'/blmrg/test_ws/Service1.svc"
      binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
      contract="IService1" name="BasicHttpBinding_IService1" />
</client>
 </system.serviceModel>
</configuration>

Proxy class: 代理类:

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public partial class Service1Client : System.ServiceModel.ClientBase<IService1>, IService1
{

    public Service1Client()
    {
    }

    public Service1Client(string endpointConfigurationName) : 
            base(endpointConfigurationName)
    {

    }

    public Service1Client(string endpointConfigurationName, string remoteAddress) : 
            base(endpointConfigurationName, remoteAddress)
    {
    }

    public Service1Client(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
            base(endpointConfigurationName, remoteAddress)
    {
    }

    public Service1Client(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
            base(binding, remoteAddress)
    {
    }

    public CitizenType GetMan(decimal id)
    {
        return base.Channel.GetMan(id);
    }

    public System.Threading.Tasks.Task<CitizenType> GetManAsync(decimal id)
    {
        return base.Channel.GetManAsync(id);
    }
}

The overload for Service1Client you're using (or the compiler thinks you're using) is the one that takes an endpoint configuration name: 您正在使用(或编译器认为您正在使用)的Service1Client的重载是采用端点配置名称的重载:

public Service1Client(string endpointConfigurationName) : 
    base(endpointConfigurationName)

But what you're passing in is Address:http://132.158.6.6:8123/blmrg/test_ws/Service1.svc; and contract 'IService1' 但是您要传递的是Address:http://132.158.6.6:8123/blmrg/test_ws/Service1.svc; and contract 'IService1' Address:http://132.158.6.6:8123/blmrg/test_ws/Service1.svc; and contract 'IService1' , apparently because of this line (though it's missing the binding and doesn't have the word "and" in it): Address:http://132.158.6.6:8123/blmrg/test_ws/Service1.svc; and contract 'IService1' ,显然是因为这一行(尽管它缺少绑定并且其中没有单词“ and”):

string endpointStr = string.Format("Address: {0}; Binding: {1}; Contract: {2}", endpoint.Address.ToString(), endpoint.Binding, endpoint.Contract);

There's no need (based on the posted code) to be using ConfigurationManager to get the client section of the config file. 无需(根据发布的代码)使用ConfigurationManager来获取配置文件的客户端部分。 You can pass in the name of the endpoint section in the constructor, like this: 您可以在构造函数中传入终结点部分的名称,如下所示:

Service1Client proxy = new Service1Client("BasicHttpBinding_IService1");

The above line will pull the necessary information from the endpoint with the name "BasicHttpBinding_IService1". 上面的行将从名称为“ BasicHttpBinding_IService1”的端点提取必要的信息。

Note there are some other overloads for the constructor as well: 请注意,构造函数还有一些其他重载:

public Service1Client(string endpointConfigurationName, string remoteAddress) : 
    base(endpointConfigurationName, remoteAddress)

This will take an endpoint configuration name and the address for the service (which is usually in the endpoint element, but perhaps you want to override it based on environments or what not). 这将使用端点配置名称和服务地址(通常在端点元素中,但也许您想根据环境或其他情况来覆盖它)。

public Service1Client(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
    base(endpointConfigurationName, remoteAddress)

Similar to the previous one, but passes in an EndpointAddress as opposed to a string . 与上一个类似,但是传入一个EndpointAddress而不是一个string

public Service1Client(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
    base(binding, remoteAddress)

This one passes in a Binding and an EndpointAddress . 这一个传入BindingEndpointAddress

暂无
暂无

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

相关问题 WCF-在http://xxxxx.xxxx/Service1.svc上没有侦听端点 - WCF - There was no endpoint listening at http://xxxxx.xxxx/Service1.svc 在https:// wserver:442 / service1.svc上没有侦听端点 - there was no endpoint listening at https://wserver:442/service1.svc “无法找到名称为...的端点元素” - “Could not find endpoint element with name…” 像http://example.com这样的输入网址在操作输入中更改为http:/example.com - Input URL like http://example.com changes to http:/example.com in action input 无法找到名称和合同的端点元素 - Could not find endpoint element with name and contract 找不到名称为WCF的端点元素 - Could not find endpoint element with name WCF 找不到与绑定BasicHttpBinding的端点匹配方案http的基地址 - Could not find a base address that matches scheme http for the endpoint with binding BasicHttpBinding 找不到与绑定WSHttpBinding的端点的scheme http匹配的基址 - Could not find a base address that matches scheme http for the endpoint with binding WSHttpBinding WCF 异常:找不到与端点的方案 http 匹配的基地址 - WCF Exception: Could not find a base address that matches scheme http for the endpoint 收到对wcfservice.svc的HTTP响应时发生错误。 这可能是由于服务端点绑定未使用HTTP协议 - An error occurred while receiving the HTTP response to wcfservice.svc. This could be due to the service endpoint binding not using the HTTP protocol
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM