[英]class library application not using the app.config file
我在使用Web服务和进行Web服务调用时遇到问题。
我正在创建将生成dll的类库应用程序,这个dll将被其他应用程序用于连接webservice.I已从第三部分收到WSDL文件并且我“添加服务引用”并使用了所有代理类创造我的肥皂体。 现在我有两个问题需要将wsse:security标头添加到我的soap消息中,如下所示
<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>
当我尝试初始化我的客户端时,我面临错误,因为找不到名称为“ICMS-Http-WSPortType”的端点元素,并且在ServiceModel客户端配置部分中收缩了'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应用程序中运行良好,但在类库应用程序中没有任何原因吗?
任何人请提出一些想法
DLL的app.config
充其量只是提醒您需要在EXE的app.config
中放置什么消耗您的DLL或使用您的DLL的网站的web.config
。
它实际上并没有被配置系统默认使用,而且有些工具(例如Add Service Reference
)会在类库项目中创建一个并且没有给出任何警告,这有点令人遗憾。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.