我正在尝试使用交通网络服务。下面给出了 SOAP 请求的示例。
我使用 WSDL 结构中的 Wsdl.exe 在 c# 中创建了一个代理类。
我认为我现在需要做的是以某种方式将“身份验证”SOAP 标头插入到方法调用的 SOAP 结构中。我不确定如何将标头添加到服务方法调用中?
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://www.inteleacst.com.au/wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Header>
<ns1:authenticate>
<SOAP-ENC:Struct>
<username>username</username>
<password>password</password>
</SOAP-ENC:Struct>
</ns1:authenticate>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:getAllTraffic>
<States SOAP-ENC:arrayType="xsd:string[3]" xsi:type="ns1:State_Arr">
<item xsi:type="xsd:string">VIC</item>
<item xsi:type="xsd:string">NSW</item>
<item xsi:type="xsd:string">NT</item>
</States>
<EventCodes SOAP-ENC:arrayType="xsd:int[1]" xsi:type="ns1:EventCode_arr">
<item xsi:type="xsd:int">802</item>
</EventCodes>
</ns1:getAllTraffic>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
这是代理类中用于调用 Web 服务方法的代码。
[System.Web.Services.Protocols.SoapRpcMethodAttribute("http://webservice.intelecast.com.au/traffic/PublicSoap/server.php#getAllTraffic", RequestNamespace="http://webservice.intelecast.com.au/traffic/PublicSoap/server.php", ResponseNamespace="http://webservice.intelecast.com.au/traffic/PublicSoap/server.php")]
[return: System.Xml.Serialization.SoapElementAttribute("return")]
public TrafficInfo[] getAllTraffic(string[] States, int[] EventCodes) {
object[] results = this.Invoke("getAllTraffic", new object[] {
States,
EventCodes});
return ((TrafficInfo[])(results[0]));
}