1. 程式人生 > >.net webserver連接soap而且還需要輸入用戶名還有密碼的方法

.net webserver連接soap而且還需要輸入用戶名還有密碼的方法

set soa java 代碼 exceptio 一個 ESS ddb runt

我們經常通過.net的webserver去調用其它項目的webserver來實現交換信息,但是如果我們交換信息的方法是采用java的soap寫的方法,而且這個方法還有加密的方法,那我們需要怎樣調用吧,下面我們先來書寫一個.net的類,這個類是用於我們傳遞參數的。
由於代碼大多我們就只貼出部分的代碼
public ClientInspector ClientInspector { get; set; }
public InspectorBehavior(ClientInspector clientInspector)
{
ClientInspector = clientInspector;
}

public InspectorBehavior()
{

}
public void Validate(ServiceEndpoint endpoint)
{ }
public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
{
}
public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
{ }
public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
{
    if (this.ClientInspector == null) throw new InvalidOperationException("Caller must supply ClientInspector.");
    clientRuntime.MessageInspectors.Add(ClientInspector);
}

}
其它我們這解決方法裏面最重要的方法還是我們下面的方法。
ProductWebServiceClient productclient = new ProductWebServiceClient();
productclient.Endpoint.Behaviors.Add(new InspectorBehavior(new ClientInspector(new SecurityHeader("用戶名", "密碼"))));
通過我們上面的代碼我們可以看出,我們這裏面最重要的方法還是使用new SecurityHeader("用戶名", "密碼"))方法將我們用戶名還有密碼傳遞過去給到用戶引用。

深圳網站建設請添加鏈接描述
https://www.sz886.com/請添加鏈接描述

.net webserver連接soap而且還需要輸入用戶名還有密碼的方法