Remove namespace declarations from web service response
Posted
by Fernando
on Stack Overflow
See other posts from Stack Overflow
or by Fernando
Published on 2010-04-30T13:54:14Z
Indexed on
2010/04/30
13:57 UTC
Read the original article
Hit count: 704
I have a web service that returns a simple object:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.4927")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.SoapTypeAttribute(Namespace="urn:CHAMADO")]
public partial class STRUCCHAMADOOUT : object, System.ComponentModel.INotifyPropertyChanged {
private string cODField;
private string mSGField;
/// <remarks/>
public string COD {
get {
return this.cODField;
}
set {
this.cODField = value;
this.RaisePropertyChanged("COD");
}
}
/// <remarks/>
public string MSG {
get {
return this.mSGField;
}
set {
this.mSGField = value;
this.RaisePropertyChanged("MSG");
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
this class was generated by wsdl.exe, based on a wsdl file provided by the client. This is the web method:
[WebMethod(MessageName="CHAMADORequest")]
[SoapRpcMethod(
Action = "urn:CHAMADO#CHAMADO",
RequestNamespace = "urn:CHAMADO",
RequestElementName = "CHAMADO",
ResponseNamespace = "",
ResponseElementName = "return",
Use = SoapBindingUse.Literal
)]
[return: XmlElement("return")]
public STRUCCHAMADOOUT CHAMADO(STRUCCHAMADOIN ENTRADA)
{
STRUCCHAMADOOUT result = new STRUCCHAMADOOUT();
try {
string str = Util.GetRequestXML();
persist(getResult<Entidades.Chamado>(str, "ENTRADA", string.Empty));
result.COD = "1";
result.MSG = "Operação realizada com sucesso";
} catch (Exception ex) {
result.COD = "0";
result.MSG = ex.Message + Environment.NewLine + ex.StackTrace;
}
return result;
}
The client is saying that his system is raising an error because the service response has namespaces declaration, just like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CHAMADOResponse xmlns="urn:CHAMADO" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<return xmlns="">
<COD xmlns="urn:CHAMADO">1</COD>
<MSG xmlns="urn:CHAMADO">Operação realizada com sucesso</MSG>
</return>
</CHAMADOResponse>
Now, I managed to remove the namespaces from COD and MSG by applying the attriute WebServiceBinding(ConformsTo = WsiProfiles.None)
to the service's class and setting ResponseNamespace
to an empty string. But CHAMADOResponse still have the namespaces declaration.
I'm pretty sure that it should not be done like that. In fact, I don't believe that the namespaces are the problem at all. This project has been hard since the begining, as we had to create services that matched legacy wsdl.
My question is: is there a way that I could remove all that namespaces declaration from the web service response?
© Stack Overflow or respective owner