By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,581 Members | 1,035 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,581 IT Pros & Developers. It's quick & easy.

.Net client having problems w/SOAP Header to Axis WS

P: n/a
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:string"
Secondarily, the Java client also specifies that the web service does not
need to understand the header
by using the following attribute: soapenv:mustUnderstand="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:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<soap:Header>
<SecurityCookie xmlns="http://some.site.com/security">
...
</SecurityCookie>
</soap:Header>
<soap:Body>
<doSomething xmlns="urn:doSomethingNS">
<Code>VU</Code>
<status>Valid</status>
<ID>43195538</ID>
</doSomething>
</soap:Body>
</soap:Envelope>

//---------- Java Client SOAP envelope -- This message will work
-----------------------
<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:SecurityCookie
soapenv:mustUnderstand="0"
xsi:type="xsd:string"
xmlns:ns1="http://some.site.com/security">
...
</ns1:SecurityCookie>
</soapenv:Header>
<soapenv:Body>
<doSomething xmlns="urn:doSomethingNS">
<Code>VU</Code>
<status>VALID</status>
<ID>1845041</ID>
</doSomething>
</soapenv:Body>
</soapenv:Envelope>
// ------------ C# client code
---------------------------------------------------------

using System;
using System.Web;
using System.Xml;
using System.IO;
using System.Diagnostics;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Web.Services;
using System.Web.Services.Protocols;
/// <remarks/>
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("c ode")]
[System.Web.Services.WebServiceBindingAttribute(Nam e="doSomethingSoapBinding", Namespace="urn:doSomethingNS")]
public class doSomethingService :
System.Web.Services.Protocols.SoapHttpClientProtoc ol
{
/// <summary>
/// securityCookie SoapHeader for authentication
/// </summary>

public securityCookie SecurityCookie;
/// Generated Method to call the web service.
public doSomethingService()
{
this.Url = "http://some.site.com/doSomething";
}

/// Function call for the method to call the web service.
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.Web.Services.Protocols.SoapDocumentMethodAt tribute("",
RequestNamespace="urn:doSomethingNS",
ResponseNamespace="urn:doSomethingNS",
Use=System.Web.Services.Description.SoapBindingUse .Literal,

ParameterStyle=System.Web.Services.Protocols.SoapP arameterStyle.Wrapped)]
[return: System.Xml.Serialization.XmlElementAttribute("doSo methingReturn")]
[System.Web.Services.Protocols.SoapHeader("Security Cookie")]
[Trace(Filename="C:\\TraceLog\\SoapTraceLog.log")]
public int
doSomething([System.Xml.Serialization.XmlElementAttribute(IsNul lable=true)]
string Code, [System.Xml.Serialization.XmlElementAttribute(IsNul lable=true)]
string status,
[System.Xml.Serialization.XmlElementAttribute(IsNul lable=true)] string ID)
{
object[] results = this.Invoke("doSomething", new object[] { Code, status,
ID} );
return ((int)(results[0]));
}

/// generated function to start an asynchronous call to the web service
public System.IAsyncResult BegindoSomething(string Code, string status,
string ID, System.AsyncCallback callback, object asyncState)
{
return this.BeginInvoke("doSomething", new object[] { Code, status, ID},
callback, asyncState);
}

/// generated function to complete an asynchronous call to the web service
public int EnddoSomething(System.IAsyncResult 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 SecurityCookieString property of this class.
/// </summary>
[System.Xml.Serialization.XmlRootAttribute(ElementN ame="SecurityCookie",
Namespace="http://some.site.com/security", IsNullable=false,
DataType="String")]
public class securityCookie : System.Web.Services.Protocols.SoapHeader
{
//[System.Xml.Serialization.XmlTextAttribute]
public string SecurityCookieString;
}

Nov 23 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.