soap envelope using C# problem

I'm trying to build a soap envelope using C#; I'm getting the error: "Specified value has invalid HTTP Header characters. Parameter name: name" when adding the header.
When I use the Immediate Window to examine the output of BuildSoapHeader(), I still see the escape sequence "\" literal and I wonder if that's the issue or if it's something else.

Please help!

    WebRequest webRequest = WebRequest.Create(this._fiserveURI);
    HttpWebRequest httpRequest = (HttpWebRequest)webRequest;
    httpRequest.Method = "POST";
    httpRequest.ContentType = "text/xml; charset=utf-8";

        private string BuildSoapHeader()
            StringBuilder retValue = new StringBuilder("<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"\" ");
            retValue.Append("xmlns:SOAP-ENC=\"\" ");
            retValue.Append("xmlns:xsi=\"\" ");
            retValue.Append("xmlns:xsd=\"\"> ");
            retValue.Append("<m:PI00WEBSOperationRequest_header xmlns:m=\"\">");
            retValue.Append("<m:DateTime>" + DateTime.Now.ToString() + "</m:DateTime>");
            retValue.Append("<m:uuid>" + this._fiserveUUID +"</m:uuid>");
            retValue.Append("<m:PrincipalPWD>" + this._fiservePrincipalPWD + "</m:PrincipalPWD>");
            retValue.Append("<m:PrincipalID>"+ this._fiservePrincipalID +"</m:PrincipalID>");
            retValue.Append("<m:VendorID>" + this._fiserveVendorID + "</m:VendorID>");
            retValue.Append("<m:AppID>" + this._fiserveAppID + "</m:AppID>");
            retValue.Append("<m:OrgID>" + this._fiserveOrgID + "</m:OrgID>");
            retValue.Append("<m:SessionID>" + this._fiserveSessionID + "</m:SessionID>");
            retValue.Append("<m:URI>" + this._fiserveURI + "</m:URI>");
            return retValue.ToString();
Miles ThorntonSenior C# Developer and TFS AdministratorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Randy PooleCommented:
can you give me a printout of the actual retValue
käµfm³d 👽Commented:
When I use the Immediate Window to examine the output of BuildSoapHeader(), I still see the escape sequence "\" literal
And you will. That's just how the Immediate Window works. See:

käµfm³d 👽Commented:
Note that you do not add a SOAP header to the HTTP request headers. It needs to go in the request body, just like the envelope body does. It's all a part of the same envelope, and that envelope needs to appear in the HTTP request body. You need to open the request stream in order to write to the request body.
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Miles ThorntonSenior C# Developer and TFS AdministratorAuthor Commented:
I am SO confused... Thank you all for your help!
I've attached the class file for your perusal.

Kaufmed, what goes in the HTTP Request header?

Clearly, I'm doing this wrong... I'd really appreciate some detailed advice.

Randy Poole, you asked, so this is what I have: "SOAP: <SOAP-ENV:Envelope xmlns:SOAP-ENV=\"\" xmlns:SOAP-ENC=\"\" xmlns:xsi=\"\" xmlns:xsd=\"\"> <SOAP-ENV:Header><m:PI00WEBSOperationRequest_header xmlns:m=\"\"><m:LSPHeader><m:Service><m:DateTime>7/12/2014 11:14:58 AM</m:DateTime><m:uuid>aaaaaaa</m:uuid></m:Service><m:Security><m:AuthenticationMaterial><m:PrincipalPWD>aaaaaaaaa</m:PrincipalPWD><m:PrincipalID>aaaaaa</m:PrincipalID></m:AuthenticationMaterial></m:Security><m:Client><m:VendorID>aaaaaa</m:VendorID><m:AppID>aaaaaa</m:AppID><m:OrgID>aaaaaaaa</m:OrgID><m:SessionID>aaa</m:SessionID></m:Client><m:DataSource><m:URI></m:URI></m:DataSource></m:LSPHeader></m:PI00WEBSOperationRequest_header></SOAP-ENV:Header></SOAP-ENV:Envelope>"
Miles ThorntonSenior C# Developer and TFS AdministratorAuthor Commented:
The Sample Header I was given:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="" xmlns:SOAP-ENC="" xmlns:xsi="" xmlns:xsd="">
<m:PI00WEBSOperationRequest_header xmlns:m="">
<m:AppID>TQAL client</m:AppID>
<SOAP-ENV:Body>refer to specific message body</SOAP-ENV:Body>

The Sample Body I was given:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="" xmlns:SOAP-ENC="" xmlns:xsi="" xmlns:xsd="">
<m:PI00WEBSOperationRequest_header xmlns:m="">
<m:PI00WEBSOperation xmlns:m="">
Miles ThorntonSenior C# Developer and TFS AdministratorAuthor Commented:
It appears that all I needed to do was add: "SOAP: " before the "<SOAP-ENV:Envelo..." part to comply with the Key: Value pair restriction and the header added just fine.

Thanks all!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
käµfm³d 👽Commented:
I haven't done raw SOAP before, so I'm unfamiliar with the spec (I usually let WCF do all of the heavy lifting for me), but as I recall there should only be two headers that vary when using SOAP. One is the Content-Type, and the other is SOAPAction, I believe. Your Content-Type appears to be OK, so I think you need to only add in the SOAPAction.


httpRequest.Headers.Add("SOAPAction", "http://server:port/WebServiceMethodName");

Open in new window

käµfm³d 👽Commented:
Do let us know how it goes adding that to the HTTP headers. I'd strongly advise you to read up on SOAP specification because you have a fundamental misunderstanding of how it works.

Good luck.
Miles ThorntonSenior C# Developer and TFS AdministratorAuthor Commented:
I applaud the Experts for their time and efforts on my behalf. I'd like to award each of those who responded with points, as I feel they deserve something, some take-away even though I got my answer through and we weren't even close here...

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Services

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.