无法在ServiceModel客户端配置部分中找到名称为“xxxxx”且合同“yyy”的端点元素

时间:2013-07-21 02:55:11

标签: c# web-services soap-client

我通过这个命令生成了一个代理 -
    svcutil.exe / language:cs /out:generatedProxy.cs /config:app.config https://service100.emedny.org:9047/MHService?wsdl

然后将生成的app.config中的元素复制到现有项目的app.config文件中。

当我尝试通过 -

访问该配置文件中的客户端时

MHSClient serviceProxy = new MHSClient(“MHSPort”);

它应该引用下面的第二个客户端:

  <client>
  <endpoint address="https://webservices.hmsa.com/EDI27X/cstc/Hipaa27XService.svc"
            binding="customBinding" 
            bindingConfiguration="wsHttpEndpoint" 
            contract="HIPAA27XServiceContract" 
            name="wsHttpEndpoint" />
  <endpoint address="https://12.23.28.113:9047/MHService" 
            binding="customBinding"
            bindingConfiguration="MHService_MHSPort" 
            contract="MHS"
            name="MHSPort" />
</client>

但我得到了错误;
无法在ServiceModel客户端配置部分中找到名称为“MHSPort”且收缩“MHS”的端点元素。这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此名称匹配的端点元素。

如果我去定义MHSClient,它会把我带到proxy.cs文件和这行;
 公共部分类MHSClient:System.ServiceModel.ClientBase,MHS


解决以下问题 -
          endptAddress = new EndpointAddress(new Uri(“uri”/ xxxx“),EndpointIdentity.CreateDnsIdentity(”xxxxxx“),addressHeaders);
            MHSClient serviceProxy = new MHSClient(b,endptAddress);

2 个答案:

答案 0 :(得分:0)

解决了以下问题 - endptAddress = new EndpointAddress(new Uri(“uri”/ xxxx“),EndpointIdentity.CreateDnsIdentity(”xxxxxx“),addressHeaders);

MHSClient serviceProxy = new MHSClient(b,endptAddress);

@Guanxi在从配置文件询问端点地址时给了我线索。
一旦我创建了端点地址,我就可以使用正确的重载来实例化/创建服务; <登记/>  var b = new CustomBinding()作为第一个参数和第二个参数,
正确的端点地址。

复杂 - WS-Security - IBM Websphere服务器互操作&lt; - &gt; wcf客户端
在Web服务的各种.NET和Visual Studio实现的上下文中......
我的

答案 1 :(得分:0)

您可能需要在服务合约接口上方设置ServiceContractAttribute的ConfigurationName属性,ConfigurationName应与您的合约名称匹配。

'VB.NET:
Imports System.ServiceModel

<ServiceContract([Namespace]:="http://yournamespace", ConfigurationName:="MHS")> _
Public Interface MHS

//C#:
using System.ServiceModel;

[ServiceContract(Namespace="http://yournamespace", ConfigurationName="MHS")]
public interface MHS

在这里查看自动生成的代码: MSDN: How to: Create a Windows Communication Foundation Client

另外值得一看: MSDN: ServiceContractAttribute Class

相关问题