nastoski
Technical User
- Oct 21, 2003
- 21
Hi,
Recently I have started a project where one of the main tasks is to create a client for AXIS Web service. Our vendor has provided wsdl and some API programmer documentation. Let me just add that our client environment is .NET 2.0. According to the documentation each operation (web service method call) is authenticated and authorized by checking the user and password elements in the SOAP header. Both the user and password elements are expected in clear text:
<soapenv:Header>
<USER soapenv:mustUnderstand="0" xsi:type="xsd:string">apiuser</USER>
<PASSWORD soapenv:mustUnderstand="0" xsi:type="xsd:string">apiuser</ PASSWORD>
</soapenv:Header>
For that reason I have create a new class header that inherit from SoapHeader class
public class header : SoapHeader
{
public string USER;
public string PASSWORD;
}
I have add web reference from provided wsdl and the proxy class has been created. In proxy class I have declare a variable head of type header
public header head;
I have modified an initial method from proxy class that I’m trying to invoke from
[System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace=" ResponseNamespace="]
[return:System.Xml.Serialization.SoapElementAttribute("retrieveReturn")]
public ManagedEntityValue retrieve(string in0, ManagedEntityKey in1) {
object[] results = this.Invoke("retrieve", new object[] {in0,
in1});
return ((ManagedEntityValue)(results[0]));
}
To
[System.Web.Services.Protocols.SoapRpcMethodAttribute("",RequestNamespace=" ResponseNamespace="]
[return:System.Xml.Serialization.SoapElementAttribute("retrieveReturn")]
[SoapHeader("head", Direction=SoapHeaderDirection.In)]
public ManagedEntityValue retrieve(string in0, ManagedEntityKey in1) {
head = new header();
head.USER = "admin";
head.PASSWORD = "admin";
object[] results = this.Invoke("retrieve", new object[] {in0,
in1});
return ((ManagedEntityValue)(results[0]));
}
When I run the project an exception is thrown saying:
“Content: APIAuthenticationException: Authentication failed.”
During debugging I have started Network Monitor tool in order to inspect what I am sending to AXIS web service. The header is included in soap request and send towards AXIS WS but in following format:
<soap:Header>
<types: header id="h_id1">
<USER xsi:type="xsd:string">apiuser</USER>
<PASSWORD xsi:type="xsd:string">apiuser</PASSWORD>
</types:header>
</soap:Header>
Obviously there is a discrepancy between header format that I am generating with required one by AXIS WS, i.e. a tag <types: header id="h_id1"> is causing the problems and generation of exception on Web service side. My question is how can I remove this tag, is there some option to do this by using SoapHeader class, or SoapExtension class? Or maybe should I completely customize the header? I have tried with adding some SoapType attributes
[SoapType(Namespace="")]
public class header : SoapHeader
{
public string USER;
public string PASSWORD;
}
but it didn’t help. After applying this change, header that is generated looks like:
<soap:Header>
<header id="h_id1">
<USER xsi:type="xsd:string">apiuser</USER>
<PASSWORD xsi:type="xsd:string">apiuser</PASSWORD>
</header>
</soap:Header>
meaning that only NamespacePrefix value “types” is removed, which also cause the same problems and throwing of the same exception.
I have checked for similar problems on internet, found some forums question way back in history with no proposed solution. Can you please help me? Any suggestion, articles, code examples or any explanations is most welcomed. Thank you in advance.
Igor
Recently I have started a project where one of the main tasks is to create a client for AXIS Web service. Our vendor has provided wsdl and some API programmer documentation. Let me just add that our client environment is .NET 2.0. According to the documentation each operation (web service method call) is authenticated and authorized by checking the user and password elements in the SOAP header. Both the user and password elements are expected in clear text:
<soapenv:Header>
<USER soapenv:mustUnderstand="0" xsi:type="xsd:string">apiuser</USER>
<PASSWORD soapenv:mustUnderstand="0" xsi:type="xsd:string">apiuser</ PASSWORD>
</soapenv:Header>
For that reason I have create a new class header that inherit from SoapHeader class
public class header : SoapHeader
{
public string USER;
public string PASSWORD;
}
I have add web reference from provided wsdl and the proxy class has been created. In proxy class I have declare a variable head of type header
public header head;
I have modified an initial method from proxy class that I’m trying to invoke from
[System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace=" ResponseNamespace="]
[return:System.Xml.Serialization.SoapElementAttribute("retrieveReturn")]
public ManagedEntityValue retrieve(string in0, ManagedEntityKey in1) {
object[] results = this.Invoke("retrieve", new object[] {in0,
in1});
return ((ManagedEntityValue)(results[0]));
}
To
[System.Web.Services.Protocols.SoapRpcMethodAttribute("",RequestNamespace=" ResponseNamespace="]
[return:System.Xml.Serialization.SoapElementAttribute("retrieveReturn")]
[SoapHeader("head", Direction=SoapHeaderDirection.In)]
public ManagedEntityValue retrieve(string in0, ManagedEntityKey in1) {
head = new header();
head.USER = "admin";
head.PASSWORD = "admin";
object[] results = this.Invoke("retrieve", new object[] {in0,
in1});
return ((ManagedEntityValue)(results[0]));
}
When I run the project an exception is thrown saying:
“Content: APIAuthenticationException: Authentication failed.”
During debugging I have started Network Monitor tool in order to inspect what I am sending to AXIS web service. The header is included in soap request and send towards AXIS WS but in following format:
<soap:Header>
<types: header id="h_id1">
<USER xsi:type="xsd:string">apiuser</USER>
<PASSWORD xsi:type="xsd:string">apiuser</PASSWORD>
</types:header>
</soap:Header>
Obviously there is a discrepancy between header format that I am generating with required one by AXIS WS, i.e. a tag <types: header id="h_id1"> is causing the problems and generation of exception on Web service side. My question is how can I remove this tag, is there some option to do this by using SoapHeader class, or SoapExtension class? Or maybe should I completely customize the header? I have tried with adding some SoapType attributes
[SoapType(Namespace="")]
public class header : SoapHeader
{
public string USER;
public string PASSWORD;
}
but it didn’t help. After applying this change, header that is generated looks like:
<soap:Header>
<header id="h_id1">
<USER xsi:type="xsd:string">apiuser</USER>
<PASSWORD xsi:type="xsd:string">apiuser</PASSWORD>
</header>
</soap:Header>
meaning that only NamespacePrefix value “types” is removed, which also cause the same problems and throwing of the same exception.
I have checked for similar problems on internet, found some forums question way back in history with no proposed solution. Can you please help me? Any suggestion, articles, code examples or any explanations is most welcomed. Thank you in advance.
Igor