关于C#调用JavaWebservice传递验证信息SoapHeader问题
最近做单点登录,对方是java开发的Axis1.4 webService,调用其login方法时需客户端传递一些验证头,对方提供的xml模板如下:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<ns1:appID soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0" xmlns:ns1="Authorization">appID</ns1:appID>
<ns2:appSign soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0" xmlns:ns2="Authorization">appSign</ns2:appSign>
</soapenv:Header>
<soapenv:Body>
<login xmlns="http://bistore.gmcc.net">
<userName>sds</userName>
<password>sd</password>
</login>
</soapenv:Body>
</soapenv:Envelope>
然而我通过以下代码定义一个SoapHeader类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services.Protocols;
namespace test
{
[System.Web.Services.WebServiceBindingAttribute(Name = "ckpSoapBinding", Namespace = "Authentication")]
public class Authentication : SoapHeader
{
public string appID;
public string appSign;
public string AppID
{
get { return appID; }
set { appID = value; }
}
public string AppSign
{
get { return appSign; }
set { appSign = value; }
}
public Authentication() { }
}
}
在调用service里的login方法前实例化一个Authentication对象MyHeader,再在webservice代理类reference.cs里login方法前添加[SoapHeader("MyHeader")],最后发现SoapHeader传递过去了,但是与对方要求接受格式不一样,发送的xml结构如下:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tns="Authentication" xmlns:types="Authentication/encodedTypes"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<types:appID id="h_id1">
<appID xsi:type="xsd:string">APP_4709347320975395</appID ></tyes:appID>
<types:appID id="h_id2">
<appSign xsi:type="xsd:string">b3743902434934793027</appSign >
</types:appSign >
</soap:Header>
</soap:Envelope>
问题来了,对方不能解析出appID和appSign,请问怎么用SoapHeader封装成对方提供的XML的格式?
困扰很久了,请求高手指点。