1
我正在使用.Net 4.5.1編寫的客戶端軟件。該軟件支持調用不同的Web服務,其中一些受WS-Security保護,其中一些不受保護。動態調用WS-Security保護的Web服務
有沒有什麼方法可以發送一些嵌入WS-Security的請求,而有些請求不是?
非常感謝
我正在使用.Net 4.5.1編寫的客戶端軟件。該軟件支持調用不同的Web服務,其中一些受WS-Security保護,其中一些不受保護。動態調用WS-Security保護的Web服務
有沒有什麼方法可以發送一些嵌入WS-Security的請求,而有些請求不是?
非常感謝
每次調用服務具有應用程序的配置文件中自己的設置。
下面是從the MSDN article 'Client Configuration'複製的示例app.config
。請注意,您調用的每個服務都有一個endpoint
元素,並且每個元素都可以引用binding
配置。 WS-security配置在綁定元素上完成,有關WCF安全性的文檔,請參閱here。基本上,您必須將安全模式設置爲Message
以使用請求和響應的WS安全加密。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<client>
<endpoint
name="endpoint1"
address="http://localhost/ServiceModelSamples/service.svc"
binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IHello"
behaviorConfiguration="IHello_Behavior"
contract="IHello" >
<metadata>
<wsdlImporters>
<extension
type="Microsoft.ServiceModel.Samples.WsdlDocumentationImporter, WsdlDocumentation"/>
</wsdlImporters>
</metadata>
<identity>
<servicePrincipalName value="host/localhost" />
</identity>
</endpoint>
// Add another endpoint by adding another <endpoint> element.
<endpoint
name="endpoint2">
//Configure another endpoint here.
</endpoint>
</client>
//The bindings section references by the bindingConfiguration endpoint attribute.
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IHello"
bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard">
<readerQuotas maxDepth="32"/>
<reliableSession ordered="true"
enabled="false" />
<security mode="Message">
//Security settings go here.
</security>
</binding>
<binding name="Another Binding"
//Configure this binding here.
</binding>
</wsHttpBinding>
</bindings>
//The behavior section references by the behaviorConfiguration endpoint attribute.
<behaviors>
<endpointBehaviors>
<behavior name=" IHello_Behavior ">
<clientVia />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
感謝您的回答。事實上,我不知道提前提供什麼服務。用戶可以通過UI提供服務,我們將發現提供的服務,並調用所選服務用戶的具體方法。其中一些調用需要WS-Security,但有些不需要 – user132706
在這種情況下,您將不得不在代碼中創建端點,綁定和行爲對象。 – codeape
我只能知道我在運行時連接了什麼服務,如果我知道服務提前,我找到了在代碼中創建端點和綁定的方法。但是,如果我不知道該服務,我找到了一種用反射調用Web服務的方法,類似於這篇文章:https://vaibhavgaikwad.wordpress.com/web-services-with-reflection-in-net/。但在這種情況下,我不知道如何支持WS-Security – user132706