我在使用web服务和进行web服务调用时遇到了问题。
我正在创建一个类库应用程序,该应用程序将生成dll,并且其他应用程序将使用该dll来连接web服务。我从第三方接收了WSDL文件,使用“添加服务引用”并使用所有代理类来创建我的soap主体。现在我有两个问题,我需要像下面这样添加wsse:security头到我的soap消息中:
为了处理这个问题并连接WebService端点地址,我修改了我的app.config文件(当添加服务引用时生成的),将其作为头标记包含在内。以下是我的app.config文件:
当我尝试按照下面的方式初始化我的客户端时,我遇到了以下错误:“在ServiceModel客户端配置部分中找不到名称为'ICMS-Http-WSPortType'和合同'Ihlth_Service.ICMSHttpWSPortType'的终结点元素。这可能是因为您的应用程序找不到配置文件,或者因为找不到与此名称匹配的终结点元素。”
我正在创建一个类库应用程序,该应用程序将生成dll,并且其他应用程序将使用该dll来连接web服务。我从第三方接收了WSDL文件,使用“添加服务引用”并使用所有代理类来创建我的soap主体。现在我有两个问题,我需要像下面这样添加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>
为了处理这个问题并连接WebService端点地址,我修改了我的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文件或者让我的代码引用该配置文件以获取信息,而不是在代码内部提供信息。
这整段代码在Windows应用程序中通过读取app.config文件运行良好,但在类库应用程序中却不行。这背后是否有什么原因?
请有经验的人提供一些想法。