5

我通过这个命令生成了一个代理 -
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);

4

2 回答 2

1

通过以下方式解决
- 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 服务器互操作 <-> wcf 客户端
在各种 .NET 和 Web 服务的 Visual Studio 实现的上下文中......
哦,我的

于 2013-07-21T16:45:56.023 回答
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 类

于 2014-04-09T08:07:36.377 回答