0

Let me start this by saying I know prefix should not matter for xml that follows standards. I am forced to use a web service that requires the request to look like this

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:prefix="http://www.url.com">
<soapenv:Header/>
<soapenv:Body>
  <prefix:Search>
     <SearchCriteria>
        <registrationStatus>A</registrationStatus>
        <startDate/>
        <endDate/>
     </SearchCriteria>
  </prefix:Search>
</soapenv:Body>
</soapenv:Envelope>

When I generate my request it ends up looking like this

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://www.url.com">
<soapenv:Header/>
<soapenv:Body>
   <Search (also tried here xmlns="http://www.url.com")>
      <SearchCriteria>
         <registrationStatus>A</registrationStatus>
         <startDate/>
         <endDate/>
      </SearchCriteria>
   </Search>
</soapenv:Body>
</soapenv:Envelope>

Because the prefix is missing I get an error saying it can't find the search child. Using fiddler I have recomposed this message a million different ways and all fails unless I add the prefix and the namespace for it. I don't own the web service and the owner won't make changes so I am stuck trying to figure it out.

My question is how can I add the prefix and the namespace to the request? I have added the service to my c# console test app using add service reference, I tried modifying the qualified and not qualified settings but that did not add the prefix.

Jim
  • 808
  • 2
  • 11
  • 28
  • "When I generate my request" does not provide enough information on why your XML is created wrong. It is somewhat surprising as VS usually generates proxy correctly and people who decide to go with "create web service request manually" route normally know how to deal with namespaces in XML... – Alexei Levenkov May 25 '14 at 19:26
  • thanks for the constructive yet useless information – Jim May 25 '14 at 19:53
  • Can your class `Search` – rene May 25 '14 at 20:04
  • It's not about your prefix. It's because the namespace is wrong. You needed to set the namespace in the `Search` object. – John Saunders May 26 '14 at 03:38
  • HI John, you are correct on that. When cleaning up the xml for security reasons I forgot to show that piece. I did have it on there and it still complained at the root and element level. I have updated the question to show this. By using my below answer I was able to modify the xml before being sent across the wire and it worked. – Jim May 26 '14 at 13:30

2 Answers2

0

I was able to find a good solution here Intercept SOAP messages from and to a web service at the client

This worked perfectly for anyone else looking to do the same

Community
  • 1
  • 1
Jim
  • 808
  • 2
  • 11
  • 28
0

i think you have to provide targetnamepace for your class Search.

Rahul Singh
  • 781
  • 11
  • 27