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";
    httpRequest.Headers.Add(this.BuildSoapHeader());
    ...

        private string BuildSoapHeader()
        {
            StringBuilder retValue = new StringBuilder("<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" ");
            retValue.Append("xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" ");
            retValue.Append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ");
            retValue.Append("xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"> ");
            retValue.Append("<SOAP-ENV:Header>");
            retValue.Append("<m:PI00WEBSOperationRequest_header xmlns:m=\"http://www.FiservLSP.RequestHeader.com\">");
            retValue.Append("<m:LSPHeader>");
            retValue.Append("<m:Service>");
            retValue.Append("<m:DateTime>" + DateTime.Now.ToString() + "</m:DateTime>");
            retValue.Append("<m:uuid>" + this._fiserveUUID +"</m:uuid>");
            retValue.Append("</m:Service>");
            retValue.Append("<m:Security>");
            retValue.Append("<m:AuthenticationMaterial>");
            retValue.Append("<m:PrincipalPWD>" + this._fiservePrincipalPWD + "</m:PrincipalPWD>");
            retValue.Append("<m:PrincipalID>"+ this._fiservePrincipalID +"</m:PrincipalID>");
            retValue.Append("</m:AuthenticationMaterial>");
            retValue.Append("</m:Security>");
            retValue.Append("<m:Client>");
            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:Client>");
            retValue.Append("<m:DataSource>");
            retValue.Append("<m:URI>" + this._fiserveURI + "</m:URI>");
            retValue.Append("</m:DataSource>");
            retValue.Append("</m:LSPHeader>");
            retValue.Append("</m:PI00WEBSOperationRequest_header>");
            retValue.Append("</SOAP-ENV:Header>");
            //retValue.Append("<SOAP-ENV:Body></SOAP-ENV:Body>");
            retValue.Append("</SOAP-ENV:Envelope>");
            return retValue.ToString();
        }
LVL 1
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
0
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:

Screenshot
0
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.
0
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=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"> <SOAP-ENV:Header><m:PI00WEBSOperationRequest_header xmlns:m=\"http://www.FiservLSP.RequestHeader.com\"><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>http://www.PI00WEBS.FWSI1027.Request.com</m:URI></m:DataSource></m:LSPHeader></m:PI00WEBSOperationRequest_header></SOAP-ENV:Header></SOAP-ENV:Envelope>"
Fiserve.cs
0
Miles ThorntonSenior C# Developer and TFS AdministratorAuthor Commented:
The Sample Header I was given:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Header>
<m:PI00WEBSOperationRequest_header xmlns:m="http://www.FiservLSP.RequestHeader.com">
<m:LSPHeader>
<m:Service>
<m:DateTime>aaaaaaaaaaaaaaaaaaaaaaaaa</m:DateTime>
<m:uuid>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</m:uuid>
</m:Service>
<m:Security>
<m:AuthenticationMaterial>
<m:PrincipalPWD>aaaaaaaaaaaa</m:PrincipalPWD>
<m:PrincipalID>aaaaaaaaaaaaaaaaaaaaaaaa</m:PrincipalID>
</m:AuthenticationMaterial>
</m:Security>
<m:Client>
<m:VendorID>D9XXXX</m:VendorID>
<m:AppID>TQAL client</m:AppID>
<m:OrgID>TPQLXXX</m:OrgID>
<m:SessionID>aaaaaaaaaa</m:SessionID>
</m:Client>
<m:DataSource>
<m:URI>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</m:URI>
</m:DataSource>
</m:LSPHeader>
</m:PI00WEBSOperationRequest_header>
</SOAP-ENV:Header>
<SOAP-ENV:Body>refer to specific message body</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

The Sample Body I was given:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Header>
<m:PI00WEBSOperationRequest_header xmlns:m="http://www.FiservLSP.RequestHeader.com">
<m:LSPHeader></m:LSPHeader>
</m:PI00WEBSOperationRequest_header>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<m:PI00WEBSOperation xmlns:m="http://www.PI00WEBS.FWSI1027.Request.com">
<m:Request>
<m:AccountNumber>0</m:AccountNumber>
</m:Request>
</m:PI00WEBSOperation>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
0
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!
0

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.

e.g.

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

Open in new window

0
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.
0
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 StackOverflow.com and we weren't even close here...

Peace,
MilesT
0
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.