I have seen many SO answers but non seem to help with the issue I have. What I am doing is calling a SOAP service from third party and it actually requires a prefix on element names. Example:
<pref:test>test</pref:test>
I have created a client using Add service reference in VS. I have a class which is where i want the prefix on each property.
public class WebsiteSoapHeader : System.Web.Services.Protocols.SoapHeader
{
public WebsiteSoapHeader()
{
xmlns.Add("test", "https://xxx/service");
}
[XmlNamespaceDeclarations]
public XmlSerializerNamespaces xmlns = new XmlSerializerNamespaces();
[XmlElement(ElementName ="test",Namespace = "https://xxx/service")]
public string testprop { get; set; }
}
As this does not get serialized manually it only produces
<test xmlns="">test</test>
If this fixed your issue then please 'Mark as Answer'
I saw this but mine is a auto generated proxy from wsdl and i don't have those methods to work with. At this point i'm using a manual approach with stringbuilder but not very clean.
If this fixed your issue then please 'Mark as Answer'
>> I saw this but mine is a auto generated proxy from wsdl and i don't have those methods to work with
How did you use the generated proxy? I suggest you replace the binding in client side. For my above link, it set below code for service, you could also set it for client binding.
Binding binding = ReplacePrefixMessageEncodingBindingElement.ReplaceEncodingBindingElement(
new WSHttpBinding(SecurityMode.None),
namespaceToPrefixMapping);
In addition, the link below shares another way to custom the Prefix.
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Participant
883 Points
294 Posts
C# XML Element Prefix SOAP
Mar 27, 2017 07:15 AM|ammd|LINK
I have seen many SO answers but non seem to help with the issue I have. What I am doing is calling a SOAP service from third party and it actually requires a prefix on element names. Example:
<pref:test>test</pref:test>
I have created a client using Add service reference in VS. I have a class which is where i want the prefix on each property.
As this does not get serialized manually it only produces
<test xmlns="">test</test>
All-Star
17652 Points
3510 Posts
Re: C# XML Element Prefix SOAP
Mar 28, 2017 06:48 AM|Chris Zhao|LINK
Hi Ammd,
Take a look the following article.
#Changing prefixes in XML responses for WCF services
https://blogs.msdn.microsoft.com/carlosfigueira/2010/06/12/changing-prefixes-in-xml-responses-for-wcf-services/
Best Regards,
Chris
Participant
883 Points
294 Posts
Re: C# XML Element Prefix SOAP
Mar 28, 2017 09:56 PM|ammd|LINK
Hi Chris
I saw this but mine is a auto generated proxy from wsdl and i don't have those methods to work with. At this point i'm using a manual approach with stringbuilder but not very clean.
Contributor
3310 Points
1607 Posts
Re: C# XML Element Prefix SOAP
Mar 31, 2017 06:56 AM|Edward Z|LINK
>> I saw this but mine is a auto generated proxy from wsdl and i don't have those methods to work with
How did you use the generated proxy? I suggest you replace the binding in client side. For my above link, it set below code for service, you could also set it for client binding.
In addition, the link below shares another way to custom the Prefix.
# Customize WCF Envelope and Namespace Prefix
http://vanacosmin.ro/Articles/Read/WCFEnvelopeNamespacePrefix
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.