Link to home
Start Free TrialLog in
Avatar of Miles Thornton
Miles ThorntonFlag for United States of America

asked on

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();
        }
Avatar of Randy Poole
Randy Poole
Flag of United States of America image

can you give me a printout of the actual retValue
Avatar of kaufmed
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:

User generated image
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.
Avatar of Miles Thornton

ASKER

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
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>
ASKER CERTIFIED SOLUTION
Avatar of Miles Thornton
Miles Thornton
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

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.
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