I am having a problem with formatting a SOAP Header in a .Net client. The
client calls a Java Axis 1.1 based web service. In order to authenticate the
caller, the web service call is intercepted by another web service that
validates a security token in the header.
I have pasted my current SOAP message that my code sends as captured from a
trace function that I added. Below that is a sample SOAP message that the
developer of the web service provided. The second message was generated from
a Java Client that they used for testing.
From what I can see, the biggest differences in the header is that the Java
Client explicitly defines the security token as: xsi:type="xsd:s tring"
Secondarily, the Java client also specifies that the web service does not
need to understand the header
by using the following attribute: soapenv:mustUnd erstand="0"
I am looking for what to add/change in the C# code that invokes the web
service to attempt to match the SOAP message that works. The C# code is also
pasted below.
Any suggestions would be appreciated.
Thanks in advance,
Daniel Thune, MCSE
Systems Engineer
Control Application and Maintenance, Inc.
dt****@cam-co.org
//---------- MS.NET Client SOAP envelope -- this fails because the header
is not processed correctly -----------------------
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelop e xmlns:soap="htt p://schemas.xmlsoap .org/soap/envelope/"
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http ://www.w3.org/2001/XMLSchema">
<soap:Header>
<SecurityCook ie xmlns="http://some.site.com/security">
...
</SecurityCookie>
</soap:Header>
<soap:Body>
<doSomething xmlns="urn:doSo methingNS">
<Code>VU</Code>
<status>Valid </status>
<ID>43195538</ID>
</doSomething>
</soap:Body>
</soap:Envelope>
//---------- Java Client SOAP envelope -- This message will work
-----------------------
<soapenv:Envelo pe 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:SecurityCo okie
soapenv:mustUnd erstand="0"
xsi:type="xsd:s tring"
xmlns:ns1="http ://some.site.com/security">
...
</ns1:SecurityCoo kie>
</soapenv:Header>
<soapenv:Body >
<doSomething xmlns="urn:doSo methingNS">
<Code>VU</Code>
<status>VALID </status>
<ID>1845041</ID>
</doSomething>
</soapenv:Body>
</soapenv:Envelop e>
// ------------ C# client code
---------------------------------------------------------
using System;
using System.Web;
using System.Xml;
using System.IO;
using System.Diagnost ics;
using System.Xml.Seri alization;
using System.Componen tModel;
using System.Web.Serv ices;
using System.Web.Serv ices.Protocols;
/// <remarks/>
[System.Diagnost ics.DebuggerSte pThroughAttribu te()]
[System.Componen tModel.Designer CategoryAttribu te("code")]
[System.Web.Serv ices.WebService BindingAttribut e(Name="doSomet hingSoapBinding ", Namespace="urn: doSomethingNS")]
public class doSomethingServ ice :
System.Web.Serv ices.Protocols. SoapHttpClientP rotocol
{
/// <summary>
/// securityCookie SoapHeader for authentication
/// </summary>
public securityCookie SecurityCookie;
/// Generated Method to call the web service.
public doSomethingServ ice()
{
this.Url = "http://some.site.com/doSomething";
}
/// Function call for the method to call the web service.
[System.Diagnost ics.DebuggerSte pThroughAttribu te()]
[System.Web.Serv ices.Protocols. SoapDocumentMet hodAttribute("" ,
RequestNamespac e="urn:doSometh ingNS",
ResponseNamespa ce="urn:doSomet hingNS",
Use=System.Web. Services.Descri ption.SoapBindi ngUse.Literal,
ParameterStyle= System.Web.Serv ices.Protocols. SoapParameterSt yle.Wrapped)]
[return: System.Xml.Seri alization.XmlEl ementAttribute( "doSomethingRet urn")]
[System.Web.Serv ices.Protocols. SoapHeader("Sec urityCookie")]
[Trace(Filename= "C:\\TraceLog\\ SoapTraceLog.lo g")]
public int
doSomething([System.Xml.Seri alization.XmlEl ementAttribute( IsNullable=true )]
string Code, [System.Xml.Seri alization.XmlEl ementAttribute( IsNullable=true )]
string status,
[System.Xml.Seri alization.XmlEl ementAttribute( IsNullable=true )] string ID)
{
object[] results = this.Invoke("do Something", new object[] { Code, status,
ID} );
return ((int)(results[0]));
}
/// generated function to start an asynchronous call to the web service
public System.IAsyncRe sult BegindoSomethin g(string Code, string status,
string ID, System.AsyncCal lback callback, object asyncState)
{
return this.BeginInvok e("doSomething" , new object[] { Code, status, ID},
callback, asyncState);
}
/// generated function to complete an asynchronous call to the web service
public int EnddoSomething( System.IAsyncRe sult asyncResult)
{
object[] results = this.EndInvoke( asyncResult);
return ((int)(results[0]));
}
}
/// <summary>
/// this class added to define the soap header used for security.
/// the cookie will be retreived separately by the calling app
/// and inserted into the SecurityCookieS tring property of this class.
/// </summary>
[System.Xml.Seri alization.XmlRo otAttribute(Ele mentName="Secur ityCookie",
Namespace="http ://some.site.com/security", IsNullable=fals e,
DataType="Strin g")]
public class securityCookie : System.Web.Serv ices.Protocols. SoapHeader
{
//[System.Xml.Seri alization.XmlTe xtAttribute]
public string SecurityCookieS tring;
}