[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;
改造完毕,然后再进行访问,就会生成如下报文:
显示发送成功。