locked
Adding namespace prefix to web service request & response RRS feed

  • Question

  • Hello all,

    I have a simple webservice, "HelloWorld" with one parameter. If I look at the SOAP request generated for this webservice it shows me this:

    Code Snippet

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
    <HelloWorld xmlns="http://smsdev.no/WebServices/">
    <inpTest>string</inpTest>
    </HelloWorld>
    </soap:Body>
    </soap:Envelope>



    Very simpe! Can I some how change the xml request to look something like this? (With the "m:" as a prefix)

    Code Snippet

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
    <m:HelloWorld xmlns:m="http://smsdev.no/WebServices/">
    <m:inpTest>string</m:inpTest>
    </m:HelloWorld>
    </soap:Body>
    </soap:Envelope>


    This is what my websiervice looks like in code:

    Code Snippet

    [WebService(Namespace = "http://smsdev.no/WebServices/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    public class Service1 : System.Web.Services.WebService
    {
    [WebMethod]
    public string HelloWorld(string inpTest)
    {
    return "Input: " + inpTest; //connectToServerSocket();
    }

    Thanks in advance.

    Wednesday, May 18, 2011 11:04 AM

All replies

  • Those two XML snippets are identical.

    Is this causing you a problem of some kind?

     


    John Saunders
    WCF is Web Services. They are not two separate things.
    Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
    Use File->New Project to create Web Service Projects
    Wednesday, May 18, 2011 3:08 PM
    Moderator
  • Both xml snippets are not the same.

    There is a difference in 2nd request <Helloworld> tag which is having prefix <m: >

    <m:HelloWorld xmlns:m="http://smsdev.no/WebServices/">
    <m:inpTest>string</m:inpTest>
    </m:HelloWorld>

    I want to include prefix tag in request and its response (which is not mention in post) xmls. 

    It would be appreciated if anyone share any thoughts on this.

    Wednesday, May 18, 2011 4:56 PM
  • No, in terms of XML, the two are identical. Prefixes don't matter. Prefixes are simply abbreviations of the namespace. It is the namespace plus the local name that matters.

    <m:HelloWorld xmlns:m="http://smsdev.no/WebServices/">
    
    means the same thing as

    <HelloWorld xmlns="http://smsdev.no/WebServices/">

    They both mean an element named "HelloWorld" in the "http://smsdev.no/WebServices/" namespace.


    John Saunders
    WCF is Web Services. They are not two separate things.
    Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
    Use File->New Project to create Web Service Projects
    Wednesday, May 18, 2011 6:05 PM
    Moderator
  • Yes, Prefix only in the difference.

    Currently web service request is like 

    <soap:Body>

    <HelloWorld xmlns="http://smsdev.no/WebServices/">

    <inpTest>

    string

      </inpTest>

    </HelloWorld>

    </soap:Body>

     

    Some how I would like to change the request as below:

    <soap:Body>

    <m:HelloWorld xmlns:m="http://smsdev.no/WebServices/">

    <inpTest>

    string

      </inpTest>

    </m:HelloWorld>

    </soap:Body>

     

    If any body have any ideas on this. kindly share.

     

    Thursday, May 19, 2011 5:21 AM
  • Just so you know, any software that requires specific prefixes is broken, and does not support the XML standards.

    John Saunders
    WCF is Web Services. They are not two separate things.
    Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
    Use File->New Project to create Web Service Projects
    Thursday, May 19, 2011 5:55 AM
    Moderator
  • Hello, and sorry for bringing such an old thread back from the dead.

    But sometimes developers are forced to cooperate with people from other companies who don't care about standards and cannot be reasoned with. I have the exact same problem as tsreeram and i must say i am quite disappointed with your three unhelpful replies

    Tuesday, November 13, 2012 10:12 AM
  • I am being very helpful. There is only one XML standard. The standard does not vary by "community". Are you suggesting that Java, for instance, doesn't follow that standard?

    If you plan to use tools like XML Serialization, which follow the standards, then you must expect them to only handle actual XML, not something that happens to look sort of like XML. a to

    If you want to process something non-standard, then create your own non-standard tools. Be sure to ask your business partner for documentation on what they consider to be XML, so that your tools can properly support it.


    John Saunders
    WCF is Web Services. They are not two separate things.
    Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
    Use File->New Project to create Web Service Projects

    Tuesday, November 13, 2012 3:14 PM
    Moderator
  • Hi,

    it seems that's not possible under general circumstances , unless you go by your own way to define that .

    Tuesday, November 13, 2012 7:56 PM