[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 598
  • Last Modified:

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();
        }
0
Miles Thornton
Asked:
Miles Thornton
  • 4
  • 4
1 Solution
 
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now