Hello,
//Visual Studio 2017, C#
When I add a web reference from the WSDL it will generate a class for you that you use to make the calls to your service.
Let's call it "MyService". If I create a partial for that class, and include it in the same assembly,
I can override the "GetWebRequest" method and directly add headers.
Works well.
First request --> IO
Second request --> NIO
Exception.
catch (Exception ex) //########## --> here is the exception
{
string error = ex.Message;
string stackTrace = ex.StackTrace;
}
When I wait more than 3 seconds works too.
Change from Get to POST, nothing happen. The same.
Does anyone have a good solution? Does anyone know a possible cause?
I think the request is empty, why?
The request content type found by the client is 'text/html; charset=iso-8859-1', was expected 'text/xml'.
Error message
--
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
creating-http-header-parameters-in-a-soap-interface-in-net
protected override WebRequest GetWebRequest(Uri uri)
{
//https://stackoverflow.com/questions/28239214/creating-http-header-parameters-in-a-soap-interface-in-net
HttpWebRequest request;
request = (HttpWebRequest)base.GetWebRequest(uri);
if (PreAuthenticate)
{
NetworkCredential networkCredentials =
Credentials.GetCredential(uri, "Basic");
if (networkCredentials != null)
{
byte[] credentialBuffer = new UTF8Encoding().GetBytes(
networkCredentials.UserName + ":" +
networkCredentials.Password);
SetRequestHeader("Authorization", "Basic " + Convert.ToBase64String(credentialBuffer));
SetRequestHeader("Accept-Encoding", "gzip,deflate");
var httpRequest = request as HttpWebRequest;
if (httpRequest != null)
{
foreach (string headerName in this.requestHeaders.Keys)
{
httpRequest.Headers[headerName] = this.requestHeaders[headerName];
}
}
request.ContentType = "text/xml;charset=\"utf-8\"";
// request.Accept = "text/xml";
// request.Method = "POST";
return request; //########## --> here is the exception