views:

238

answers:

4

I've added a Service Reference for a third-party web service to my project. When i send a request to a webservice using the generated method, the request fails saying that it is missing the XML prolog.

How can I add:

<?xml version="1.0" encoding="UTF-8"?>

to the begining of the request before sending it?

This is a C# web application.

A: 

Can you share the service reference.

Use fiddler to see if that is the actual case (sniff the wire to see what is being sent)

david valentine
A: 

According the the documentation, this is a valid request:

<?xml version="1.0" encoding="UTF-8" ?>
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:fre="http://www.dwdev.com/Webservices/Freezerworks/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"&gt;
   <SOAP-ENV:Header/>
   <SOAP-ENV:Body>
      <fre:StudySamplesSearch SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt;
         <UserName xsi:type="xsd:string">myname</UserName>
         <Password xsi:type="xsd:string">mypassword</Password>
         <SearchServiceName xsi:type="xsd:string">StudySamplesSearch</SearchServiceName>
         <FieldNames xsi:type="fre:ArrayOfstring" SOAP-ENC:arrayType="xsd:string[1]">
      <string xsi:type="xsd:string">Studyname</string>
      </FieldNames>
         <Comparators xsi:type="fre:ArrayOfstring" SOAP-ENC:arrayType="xsd:string[1]">
      <string xsi:type="xsd:string">is equal to</string>
      </Comparators>
         <SearchValues xsi:type="fre:ArrayOfstring" SOAP-ENC:arrayType="xsd:string[1]">
      <string xsi:type="xsd:string">FS-101</string>
      </SearchValues>
         <Conjunctions xsi:type="fre:ArrayOfstring" SOAP-ENC:arrayType="xsd:string[]"/>
      </fre:StudySamplesSearch>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

However, this is the actual request being sent:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;
    <s:Body s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
     <q1:StudySamplesSearch xmlns:q1="http://www.dwdev.com/Webservices/Freezerworks/"&gt;
      <UserName xsi:type="xsd:string">myname</UserName>
      <Password xsi:type="xsd:string">mypassword</Password>
      <SearchServiceName xsi:type="xsd:string">StudySamplesSearch</SearchServiceName>
      <FieldNames href="#id1"/>
      <Comparators href="#id2"/>
      <SearchValues href="#id3"/>
      <Conjunctions href="#id4"/>
     </q1:StudySamplesSearch>
     <q2:Array id="id1" q2:arrayType="xsd:string[1]" xmlns:q2="http://schemas.xmlsoap.org/soap/encoding/"&gt;
      <Item>Studyname</Item>
     </q2:Array>
     <q3:Array id="id2" q3:arrayType="xsd:string[1]" xmlns:q3="http://schemas.xmlsoap.org/soap/encoding/"&gt;
      <Item>is equal to</Item>
     </q3:Array>
     <q4:Array id="id3" q4:arrayType="xsd:string[1]" xmlns:q4="http://schemas.xmlsoap.org/soap/encoding/"&gt;
      <Item>FS-101</Item>
     </q4:Array>
     <q5:Array id="id4" q5:arrayType="xsd:string[0]" xmlns:q5="http://schemas.xmlsoap.org/soap/encoding/"/&gt;
    </s:Body>
</s:Envelope>

So even when I manually add the prolog and manually send the request using SoapUI, i get additional errors. The next being: Malformed SOAP request, SOAP-ENV:Envelope element not found at root.

So it seems that I have more problems than just a missing prolog.

Adam
The two XML documents are identical. The prefix string does not matter. It's only an abbreviation of the namespace.
John Saunders
That's true, however the web service appears to look for a specific prefix. I contacted the manufacturer and they are aware that this is a bug in their web service. Until they can fix it, is there anything i can do to modify the prefix in my request before sending it?
Adam
A: 

Ok, so i'm down to one problem. My request now looks like this:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
 xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
 xmlns:tns="http://www.dwdev.com/Webservices/Freezerworks/" 
 xmlns:types="http://www.dwdev.com/Webservices/Freezerworks/encodedTypes" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
 <soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt;
  <tns:StudySamplesSearch>
   <UserName xsi:type="xsd:string">svc.soap</UserName>
   <Password xsi:type="xsd:string">p5Ns9EF</Password>
   <SearchServiceName xsi:type="xsd:string">StudySamplesSearch</SearchServiceName>
   <FieldNames href="#id1" />
   <Comparators href="#id2" />
   <SearchValues href="#id3" />
   <Conjunctions href="#id4" />
  </tns:StudySamplesSearch>
  <soapenc:Array id="id1" soapenc:arrayType="xsd:string[1]">
   <Item>Studyname</Item>
  </soapenc:Array>
  <soapenc:Array id="id2" soapenc:arrayType="xsd:string[1]">
   <Item>is equal to</Item>
  </soapenc:Array>
  <soapenc:Array id="id3" soapenc:arrayType="xsd:string[1]">
   <Item>FS-101</Item>
  </soapenc:Array>
  <soapenc:Array id="id4" soapenc:arrayType="xsd:string[0]" />
 </soap:Body>
</soap:Envelope>

However, the web service is erroring out saying SOAP-ENV:Envelope element not found at root

If I manually change the prefix from soap to SOAP-ENV the request is successful. Is there a way to specify the prefix when creating the web reference?

Adam
A: 

The 3rd-party has fixed the webservice. Problem solved.

Adam