【发布时间】:2015-09-05 04:23:37
【问题描述】:
我在使用网络服务和进行网络服务调用时遇到问题。
我正在创建将生成 dll 的类库应用程序,此 dll 将被其他应用程序用于连接 web 服务。我已从第三方收到 WSDL 文件,我“添加服务引用”并使用了所有代理类来创建我的肥皂体。现在我有两个问题需要将 wsse:security 标头添加到我的肥皂消息中,如下所示
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>username</wsse:Username>
<wsse:Password>password</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
为了处理这个问题并连接 webserivce 端点地址,我修改了我的 app.config 文件(在添加服务引用时生成)以将其包含为标头标记。下面是我的 app.config 文件
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="ICMS-Http-WSBinding">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://devs-dp-in.wellpoint.com/Claims/2.0/Get_iHealthICMS_Results"
binding="basicHttpBinding" bindingConfiguration="ICMS-Http-WSBinding"
contract="Ihlth_Service1.ICMSHttpWSPortType" name="ICMS-Http-WSPortType">
<headers>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>username</wsse:Username>
<wsse:Password>password</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</headers>
</endpoint >
</client>
</system.serviceModel>
</configuration>
当我尝试如下初始化客户端时,我遇到了错误,因为在 ServiceModel 客户端配置部分中找不到名称为“ICMS-Http-WSPortType”和合同“Ihlth_Service.ICMSHttpWSPortType”的端点元素。这可能是因为找不到您的应用程序的配置文件,或者因为在客户端元素中找不到与此名称匹配的端点元素
Service.CMSHttpWSPortTypeClient Client = new Service.CMSHttpWSPortTypeClient("ICMS-Http-WSPortType");
我修改了我的代码以在代码中创建一个绑定和端点地址并将其传递给客户端,然后它工作正常,但由于我在 app.config 文件中提供了安全信息,因此再次遇到了缺少安全标头的问题
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
EndpointAddress address = new EndpointAddress("https://devs-dp-in.wellpoint.com/Claims/2.0/Get_iHealthICMS_Results");
有什么方法可以让我读取 app.config 文件或我的代码引用该配置文件来获取信息,而不是在代码中给出。
通过读取 app.config 文件,整个代码在 windows 应用程序中运行良好,但在类库应用程序中却没有,这背后有什么原因吗?
哪位大神给点意见
【问题讨论】:
标签: c# web-services soap class-library