Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6063781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:12:24+00:00 2026-05-23T09:12:24+00:00

I’m trying to implement an UPnP MediaServer in WCF. I’m slowly getting there, but

  • 0

I’m trying to implement an UPnP MediaServer in WCF. I’m slowly getting there, but now I’ve hit a brick wall. I need to add a prefix to the ServiceContract namespace. Right now I have the following:

[ServiceContract(Namespace = "urn:schemas-upnp-org:service:ContentDirectory:1")]
public interface  IContentDirectory
{
    [OperationContract(Action = "urn:schemas-upnp-org:service:ContentDirectory:1#Browse")]
    void Browse(string ObjectID, string BrowseFlag, string Filter, ulong StartingIndex, ulong RequestedCount, string SortCriteria, out string Result, out ulong NumberReturned, out ulong TotalMatches, out ulong UpdateID);
}

This listens to the correct soap-messages. However, I need the soap-body to begin with

<u:Browse xmlns:u="urn:schemas-upnp-org:service:ContentDirectory:1">

and WCF is now listening to:

<Browse xmlns="urn:schemas-upnp-org:service:ContentDirectory:1">

How do I get the prefix there? Does it matter? Or is there another reason why the parameters are not passed into the Browse method?

UPDATE
Here’s some extra info: The following message is sent by a real UPnP control point. The parameters are not passed into the Browse method.

<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <To s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://XXXXX:8731/ContentDirectory</To>
    <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">urn:schemas-upnp-org:service:ContentDirectory:1#Browse</Action>
  </s:Header>
  <s:Body>
      <u:Browse xmlns:u="urn:schemas-upnp-org:service:ContentDirectory:1">
         <ObjectID>0</ObjectID>
         <BrowseFlag>BrowseDirectChildren</BrowseFlag>
         <Filter>*</Filter>
         <StartingIndex>0</StartingIndex>
         <RequestedCount>15</RequestedCount>
         <SortCriteria />
      </u:Browse>
   </s:Body>
</s:Envelope>

This is the request that is generated by the WCF test client. Now the parameters are passed into the Browse method:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <To s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://XXXXXX:8731/ContentDirectory</To>
    <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">urn:schemas-upnp-org:service:ContentDirectory:1#Browse</Action>
  </s:Header>
  <s:Body>
    <Browse xmlns="urn:schemas-upnp-org:service:ContentDirectory:1">
      <ObjectID>0</ObjectID>
      <BrowseFlag>BrowseMetadata</BrowseFlag>
      <Filter>*</Filter>
      <StartingIndex>0</StartingIndex>
      <RequestedCount>0</RequestedCount>
      <SortCriteria i:nil="true" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" />
    </Browse>
  </s:Body>
</s:Envelope>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:12:24+00:00Added an answer on May 23, 2026 at 9:12 am

    The two requests which you showed (one by the UPnP control point and one by the WCF Test Client) are not equivalent. The namespace of the children of the Browse element in the first (UPnP) is the empty (“”) namespace, while in the second request (WCF TC) it’s “urn:schemas-upnp-org:service:ContentDirectory:1” – the empty prefix is bound to the empty namespace unless it’s bound to another namespace, and it’s rebound in the WCF request but not on the UPnP one.

    Now, if you want the namespace of the parameters of an operation to be different than the namespace of the operation itself, you’ll have to use a message contract – that’ll get the request sent by WCF to be equivalent (modulo prefixes) to the request sent by the UPnP control point. The code below shows how a message contract would be defined to generate a request equivalent to the one you showed for the control point.

    public class StackOverflow_2495195
    {
        [MessageContract(WrapperName="Browse", WrapperNamespace="urn:schemas-upnp-org:service:ContentDirectory:1", IsWrapped=true)]
        public class BrowseRequest
        {
            [MessageBodyMember(Namespace = "", Order = 0)]
            public string ObjectID;
    
            [MessageBodyMember(Namespace = "", Order = 1)]
            public string BrowseFlag;
    
            [MessageBodyMember(Namespace = "", Order = 2)]
            public string Filter;
    
            [MessageBodyMember(Namespace = "", Order = 3)]
            public ulong StartingIndex;
    
            [MessageBodyMember(Namespace = "", Order = 4)]
            public ulong RequestedCount;
    
            [MessageBodyMember(Namespace = "", Order = 5)]
            public string SortCriteria;
        }
    
        [MessageContract(WrapperName = "BrowseResponse", WrapperNamespace = "urn:schemas-upnp-org:service:ContentDirectory:1", IsWrapped = true)]
        public class BrowseResponse
        {
            [MessageBodyMember(Namespace = "", Order = 0)]
            public string Result;
    
            [MessageBodyMember(Namespace = "", Order = 1)]
            public ulong NumberReturned;
    
            [MessageBodyMember(Namespace = "", Order = 2)]
            public ulong TotalMatches;
    
            [MessageBodyMember(Namespace = "", Order = 3)]
            public ulong UpdateID;
        }
    
        [ServiceContract(Namespace = "urn:schemas-upnp-org:service:ContentDirectory:1")]
        public interface IContentDirectory
        {
            [OperationContract(Action = "urn:schemas-upnp-org:service:ContentDirectory:1#Browse")]
            //void Browse(string ObjectID, string BrowseFlag, string Filter, ulong StartingIndex, ulong RequestedCount, string SortCriteria, out string Result, out ulong NumberReturned, out ulong TotalMatches, out ulong UpdateID);
            BrowseResponse Browse(BrowseRequest request);
        }
        public class Service : IContentDirectory
        {
            //public void Browse(string ObjectID, string BrowseFlag, string Filter, ulong StartingIndex, ulong RequestedCount, string SortCriteria, out string Result, out ulong NumberReturned, out ulong TotalMatches, out ulong UpdateID)
            //{
            //    Result = null;
            //    NumberReturned = 0;
            //    TotalMatches = 0;
            //    UpdateID = 0;
            //}
            public BrowseResponse Browse(BrowseRequest request)
            {
                return new BrowseResponse { NumberReturned = 0, Result = null, TotalMatches = 0, UpdateID = 0 };
            }
        }
        static Binding GetBinding()
        {
            return new CustomBinding(
                new TextMessageEncodingBindingElement(MessageVersion.Soap11WSAddressing10, Encoding.UTF8),
                new HttpTransportBindingElement());
        }
        public static void Test()
        {
            string baseAddress = "http://" + Environment.MachineName + ":8000/Service";
            ServiceHost host = new ServiceHost(typeof(Service), new Uri(baseAddress));
            host.AddServiceEndpoint(typeof(IContentDirectory), GetBinding(), "");
            host.Description.Behaviors.Add(new ServiceMetadataBehavior { HttpGetEnabled = true });
            host.Open();
            Console.WriteLine("Host opened");
    
            ChannelFactory<IContentDirectory> factory = new ChannelFactory<IContentDirectory>(GetBinding(), new EndpointAddress(baseAddress));
            IContentDirectory proxy = factory.CreateChannel();
            //string result;
            //ulong ul1, ul2, ul3;
            //proxy.Browse(null, null, null, 0, 0, null, out result, out ul1, out ul2, out ul3);
            proxy.Browse(new BrowseRequest { BrowseFlag = null, Filter = null, ObjectID = null, RequestedCount = 0, SortCriteria = null, StartingIndex = 0 });
    
            ((IClientChannel)proxy).Close();
            factory.Close();
    
            Console.Write("Press ENTER to close the host");
            Console.ReadLine();
            host.Close();
        }
    }
    

    Now, the request that is sent by WCF is XML-equivalent, but the prefixes are still different. It As John Saunders mentioned, it shouldn’t matter, so there’s no simple knob in WCF to let you set the prefix for the elements written in the WCF messages. You can, however, use a custom encoder to do exactly that. I posted about it a while back at http://blogs.msdn.com/b/carlosfigueira/archive/2010/06/13/changing-prefixes-in-xml-responses.aspx – you can use that example to create a custom encoder which will set the prefixes to what you expect them to be.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.