Working with SOAP and adding header info to messages

I'm very new to Web services so please be gentle! I have a Web service that returns a SOAP envelope to a client thus
 <?xml version="1.0" encoding="utf-8"?>
 <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       <SimonsXMLResult xsi:type="xsd:string">string</SimonsXMLResult>
Firstly, how I can change "<soap:Envelope " to "<env:Envelope" ? Also the my webmethod returns a string thus
 return mystr;
And the ASP.NET parser seems to do a wonderful job of encoding this as
 <soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
       <SimonsXMLResult xsi:type="xsd:string">string</SimonsXMLResult>
How can I make the return into, say for example,
 <env:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
Finally, how do I add header information to my messages. The format I'm after is something like...
       <sif:SIF_Name>blahdy blah</sif:SIF_Name>

1- Regarding the env: namespace qualifier:
I have to ask why you would want to do such a thing. The string that you use as your namespace qualifier is irrelevant. (it's basically a variable name--you just have to use it consistently within your message.) The SOAP runtime system that generates the SOAP message (in your case ASP.NET) chooses the namespace qualifier. I don't think you have the ability to tell ASP/NET to use env: rather than soap:. If you really want to do this, you have three choices:
1- use a different SOAP runtime system that uses the env: namespace qualifier
2- use a low-level API (or use a straight XML processing API) to manually construct your SOAP message
3- transform the message when you receive it using XSLT

2- Regarding the response message format:
The ASP.NET-generated response message is generated because you are using RPC/encoded. If you want to return your example message then you would need to define the service as document/literal (but in that case you would not specify the encodingStyle attribute). Instead your return message would look something like:
   <env:Body xmlns:fe="fe-namespace-uri">
3- Regarding building SOAP headers:
Here are some resources for you:
- a free article with code samples
- a for fee article that explain how to develop SOAP Headers using ASP.NET
- Rob Howard's page (see ASP.NET Advanced Web Services presentation and code samples)
This was first published in June 2003

Dig Deeper on Simple Object Access Protocol (SOAP)



Find more PRO+ content and other member only offers, here.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.



Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: