[System.Web.Services.Protocols.
SoapDocumentMethodAttribute
(
""
, RequestNamespace=
"http://webservice.notify.sys/"
, ResponseNamespace=
"http://webservice.notify.sys/"
, Use=System.Web.Services.Description.
SoapBindingUse
.Literal, ParameterStyle=System.Web.Services.Protocols.
SoapParameterStyle
.Wrapped)]
[
return
: System.Xml.Serialization.
XmlElementAttribute
(
"return"
, Form=System.Xml.Schema.
XmlSchemaForm
.Unqualified)]
[ SoapHeader( "RequestSOAPHeader")]
public
notifyTodoAppResult
setTodoDone([System.Xml.Serialization.
XmlElementAttribute
(Form=System.Xml.Schema.
XmlSchemaForm
.Unqualified)]
notifyTodoRemoveContext
arg0) {
object
[] results =
this
.Invoke(
"setTodoDone"
,
new
object
[] {
arg0});
return
((
notifyTodoAppResult
)(results[0]));
}
結果返回用戶名密碼錯誤:
查OA系統訪問文檔,才發現SOAPHeader須要放在特殊的命名空間內容,可是由於原WSDL可能由於安全緣由就沒有任何顯式聲明,通過一番折騰終於明白如何去改造WebService代理類在報文節點上面加自定義的命名空間和前綴。原報文要求以下:
<RequestSOAPHeader xmlns:tns="http://sys.webservice.client">
<tns:UserName>
username
</tns:UserName>
<tns:Password>
password
</tns:Password>
</RequestSOAPHeader>
將原有報文頭對象RequestSOAPHeader更改成:
public
class
RequestSOAPHeader
: System.Web.Services.Protocols.
SoapHeader
{
public
RequestSOAPHeader()
{
Namespaces =
new
XmlSerializerNamespaces
();
}
[
XmlElement
(Namespace =
"http://sys.webservice.client"
)]
public
string
UserName{
get
;
set
; }
[
XmlElement
(Namespace =
"http://sys.webservice.client"
)]
public
string
Password {
get
;
set
; }
[
XmlNamespaceDeclarations
]
public
XmlSerializerNamespaces
Namespaces {
get
;
set
; }
}
而後在代理類的構造函數中實例化RequestSOAPHeader對象時,將須要的命名空間定義添加到Namespaces中:
RequestSOAPHeader =
new
OA.
RequestSOAPHeader
();
RequestSOAPHeader.Namespaces.Add(
"tns"
,
"http://sys.webservice.client"
);
RequestSOAPHeader.UserName=Settings.Default.ConnectUserName;
RequestSOAPHeader.Password=Settings.Default.ConnectPassword;
改造完畢,而後再進行訪問,就會生成以下報文:
顯示發送成功。