Miles Thornton
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._fi serveURI);
HttpWebRequest httpRequest = (HttpWebRequest)webRequest ;
httpRequest.Method = "POST";
httpRequest.ContentType = "text/xml; charset=utf-8";
httpRequest.Headers.Add(th is.BuildSo apHeader() );
...
private string BuildSoapHeader()
{
StringBuilder retValue = new StringBuilder("<SOAP-ENV:E nvelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" ");
retValue.Append("xmlns:SOA P-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:PI00WE BSOperatio nRequest_h eader xmlns:m=\"http://www.FiservLSP.RequestHeader.com\">");
retValue.Append("<m:LSPHea der>");
retValue.Append("<m:Servic e>");
retValue.Append("<m:DateTi me>" + DateTime.Now.ToString() + "</m:DateTime>");
retValue.Append("<m:uuid>" + this._fiserveUUID +"</m:uuid>");
retValue.Append("</m:Servi ce>");
retValue.Append("<m:Securi ty>");
retValue.Append("<m:Authen ticationMa terial>");
retValue.Append("<m:Princi palPWD>" + this._fiservePrincipalPWD + "</m:PrincipalPWD>");
retValue.Append("<m:Princi palID>"+ this._fiservePrincipalID +"</m:PrincipalID>");
retValue.Append("</m:Authe nticationM aterial>") ;
retValue.Append("</m:Secur ity>");
retValue.Append("<m:Client >");
retValue.Append("<m:Vendor ID>" + this._fiserveVendorID + "</m:VendorID>");
retValue.Append("<m:AppID> " + this._fiserveAppID + "</m:AppID>");
retValue.Append("<m:OrgID> " + this._fiserveOrgID + "</m:OrgID>");
retValue.Append("<m:Sessio nID>" + this._fiserveSessionID + "</m:SessionID>");
retValue.Append("</m:Clien t>");
retValue.Append("<m:DataSo urce>");
retValue.Append("<m:URI>" + this._fiserveURI + "</m:URI>");
retValue.Append("</m:DataS ource>");
retValue.Append("</m:LSPHe ader>");
retValue.Append("</m:PI00W EBSOperati onRequest_ header>");
retValue.Append("</SOAP-EN V:Header>" );
//retValue.Append("<SOAP-E NV:Body></ SOAP-ENV:B ody>");
retValue.Append("</SOAP-EN V:Envelope >");
return retValue.ToString();
}
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._fi
HttpWebRequest httpRequest = (HttpWebRequest)webRequest
httpRequest.Method = "POST";
httpRequest.ContentType = "text/xml; charset=utf-8";
httpRequest.Headers.Add(th
...
private string BuildSoapHeader()
{
StringBuilder retValue = new StringBuilder("<SOAP-ENV:E
retValue.Append("xmlns:SOA
retValue.Append("xmlns:xsi
retValue.Append("xmlns:xsd
retValue.Append("<SOAP-ENV
retValue.Append("<m:PI00WE
retValue.Append("<m:LSPHea
retValue.Append("<m:Servic
retValue.Append("<m:DateTi
retValue.Append("<m:uuid>"
retValue.Append("</m:Servi
retValue.Append("<m:Securi
retValue.Append("<m:Authen
retValue.Append("<m:Princi
retValue.Append("<m:Princi
retValue.Append("</m:Authe
retValue.Append("</m:Secur
retValue.Append("<m:Client
retValue.Append("<m:Vendor
retValue.Append("<m:AppID>
retValue.Append("<m:OrgID>
retValue.Append("<m:Sessio
retValue.Append("</m:Clien
retValue.Append("<m:DataSo
retValue.Append("<m:URI>" + this._fiserveURI + "</m:URI>");
retValue.Append("</m:DataS
retValue.Append("</m:LSPHe
retValue.Append("</m:PI00W
retValue.Append("</SOAP-EN
//retValue.Append("<SOAP-E
retValue.Append("</SOAP-EN
return retValue.ToString();
}
can you give me a printout of the actual retValue
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.
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:PI00WE BSOperatio nRequest_h eader xmlns:m=\"http://www.FiservLSP.RequestHeader.com\"><m:LSPHeader>< m:Service> <m:DateTim e>7/12/201 4 11:14:58 AM</m:DateTime><m:uuid>aaa aaaa</m:uu id></m:Ser vice><m:Se curity><m: Authentica tionMateri al><m:Prin cipalPWD>a aaaaaaaa</ m:Principa lPWD><m:Pr incipalID> aaaaaa</m: PrincipalI D></m:Auth entication Material>< /m:Securit y><m:Clien t><m:Vendo rID>aaaaaa </m:Vendor ID><m:AppI D>aaaaaa</ m:AppID><m :OrgID>aaa aaaaa</m:O rgID><m:Se ssionID>aa a</m:Sessi onID></m:C lient><m:D ataSource> <m:URI>http://www.PI00WEBS.FWSI1027.Request.com</m :URI></m:D ataSource> </m:LSPHea der></m:PI 00WEBSOper ationReque st_header> </SOAP-ENV :Header></ SOAP-ENV:E nvelope>"
Fiserve.cs
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:PI00WE
Fiserve.cs
ASKER
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:PI00WEBSOperationReques t_header xmlns:m="http://www.FiservLSP.RequestHeader.com">
<m:LSPHeader>
<m:Service>
<m:DateTime>aaaaaaaaaaaaaa aaaaaaaaaa a</m:DateT ime>
<m:uuid>aaaaaaaaaaaaaaaaaa aaaaaaaaaa aaaaaaaa</ m:uuid>
</m:Service>
<m:Security>
<m:AuthenticationMaterial>
<m:PrincipalPWD>aaaaaaaaaa aa</m:Prin cipalPWD>
<m:PrincipalID>aaaaaaaaaaa aaaaaaaaaa aaa</m:Pri ncipalID>
</m:AuthenticationMaterial >
</m:Security>
<m:Client>
<m:VendorID>D9XXXX</m:Vend orID>
<m:AppID>TQAL client</m:AppID>
<m:OrgID>TPQLXXX</m:OrgID>
<m:SessionID>aaaaaaaaaa</m :SessionID >
</m:Client>
<m:DataSource>
<m:URI>aaaaaaaaaaaaaaaaaaa aaaaaaaaaa aaa</m:URI >
</m:DataSource>
</m:LSPHeader>
</m:PI00WEBSOperationReque st_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:PI00WEBSOperationReques t_header xmlns:m="http://www.FiservLSP.RequestHeader.com">
<m:LSPHeader></m:LSPHeader >
</m:PI00WEBSOperationReque st_header>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<m:PI00WEBSOperation xmlns:m="http://www.PI00WEBS.FWSI1027.Request.com">
<m:Request>
<m:AccountNumber>0</m:Acco untNumber>
</m:Request>
</m:PI00WEBSOperation>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
<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:PI00WEBSOperationReques
<m:LSPHeader>
<m:Service>
<m:DateTime>aaaaaaaaaaaaaa
<m:uuid>aaaaaaaaaaaaaaaaaa
</m:Service>
<m:Security>
<m:AuthenticationMaterial>
<m:PrincipalPWD>aaaaaaaaaa
<m:PrincipalID>aaaaaaaaaaa
</m:AuthenticationMaterial
</m:Security>
<m:Client>
<m:VendorID>D9XXXX</m:Vend
<m:AppID>TQAL client</m:AppID>
<m:OrgID>TPQLXXX</m:OrgID>
<m:SessionID>aaaaaaaaaa</m
</m:Client>
<m:DataSource>
<m:URI>aaaaaaaaaaaaaaaaaaa
</m:DataSource>
</m:LSPHeader>
</m:PI00WEBSOperationReque
</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:PI00WEBSOperationReques
<m:LSPHeader></m:LSPHeader
</m:PI00WEBSOperationReque
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<m:PI00WEBSOperation xmlns:m="http://www.PI00WEBS.FWSI1027.Request.com">
<m:Request>
<m:AccountNumber>0</m:Acco
</m:Request>
</m:PI00WEBSOperation>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
e.g.
httpRequest.Headers.Add("SOAPAction", "http://server:port/WebServiceMethodName");
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.
Good luck.
ASKER
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
Peace,
MilesT