consume service SOAP in c# error SSL

Have a great idea for extending Zimbra? Share ideas, ask questions, contribute, and get feedback.
germangc125
Posts: 1
Joined: Mon Jun 27, 2016 4:06 pm

consume service SOAP in c# error SSL

Postby germangc125 » Mon Jun 27, 2016 4:33 pm

Hi,

i need help, I try to connect to zimbra services soap from c# and I get the error: The connection is completed: Unable to establish a relationship of trust secure channel for SSL / TLS, .
i read documentation but nothing. when making the requeste me the error occurs, I must have a safety certificate provided by zimbra? -- thanks in what I can help

I am using this code I found here in the forum:

// is method what call for create account in zimbra
public static void CreateNewZimbraAccount(string username, string domainName, string firstName, string lastName)
{
SoapParameters myParam = new SoapParameters()
{
accountUsername = string.Format("{0}@{1}", username, domainName),
accountFirstName = firstName,
accountLastName = lastName,
};
AccountService.Create(myParam);
}

// class AccountService

public static void Create(SoapParameters param)
{
GetAdministratorAuthenticationToken(param);
CreateAccountRequest(param);
}

private static void GetAdministratorAuthenticationToken(SoapParameters param)
{
XmlDocument doc = GetResponseDoc(param, SoapMessages.AuthenticationToken);
param.authToken = doc.GetElementsByTagName("authToken").Item(0).InnerXml;
}

private static XmlDocument GetResponseDoc(SoapParameters param, SoapMessages message)
{
string soapMessage = SoapMessageBuilder(message, param);
XmlDocument requestDoc = new XmlDocument();
requestDoc.LoadXml(soapMessage);
HttpWebRequest request = HttpWebRequestBuilder(param.serviceAdminSoapUri);
Stream stm = request.GetRequestStream();
requestDoc.Save(stm);
stm.Close();
WebResponse resp = request.GetResponse(); <- here occurs error --------------------- Unable to establish a relationship of trust secure channel for SSL / TLS, .
stm = resp.GetResponseStream();
StreamReader r = new StreamReader(stm);
XmlDocument responseDoc = new XmlDocument();
responseDoc.LoadXml(r.ReadToEnd());
return responseDoc;
}

private static HttpWebRequest HttpWebRequestBuilder(string serviceAdminSoapUri)
{
HttpWebRequest retVal = (HttpWebRequest)WebRequest.Create(serviceAdminSoapUri);
retVal.Headers.Add("SOAPAction", "''");
retVal.ContentType = "text/xml;charset='utf - 8 '";
retVal.Accept = "text/xml";
retVal.Method = "POST";
return retVal;
}

private static string SoapMessageBuilder(SoapMessages message, SoapParameters param){
string retVal = "";
switch(message)
{
case SoapMessages.AuthenticationToken :
retVal = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
"<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\">" +
"<soap:Header>" +
"<context xmlns=\"urn:zimbra\">" +
"<format type=\"xml\"/>" +
"</context>" +
"</soap:Header>" +
"<soap:Body>" +
"<AuthRequest xmlns=\"urn:zimbraAdmin\">" +
"<account by=\"name\">cuenta@</account>" +
"<password>Clave segura</password>" +
"</AuthRequest>" +
"</soap:Body>" +
"</soap:Envelope>";

break;
return retVal;

}
}

public SoapParameters()
{
string impersonateDomain = System.Configuration.ConfigurationSettings.AppSettings["Domain.Settings.ImpersonateDomain"];
string impersonateUsername = System.Configuration.ConfigurationSettings.AppSettings["Domain.Settings.ImpersonateUsername"];
string impersonatePassword = System.Configuration.ConfigurationSettings.AppSettings["Domain.Settings.ImpersonatePassword"];
string zimbraServiceAdminSoapUri = System.Configuration.ConfigurationSettings.AppSettings["Domain.Settings.ZimbraServiceAdminSoapUri"];
adminUsername = string.Format("{0}@{1}", impersonateUsername, impersonateDomain);
adminPassword = impersonatePassword;
serviceAdminSoapUri = zimbraServiceAdminSoapUri;
}
private static void CreateAccountRequest(SoapParameters param)
{
XmlDocument doc = GetResponseDoc(param, SoapMessages.CreateAccount);
try
{
string value = doc.GetElementsByTagName("CreateAccountResponse").Item(0).ChildNodes[0].Attributes["id"].Value;
Guid guid = new Guid(value);
param.accountId = guid.ToString();
}
catch
{
throw new Exception("Account Did Not Appear To Be Created.");
}
}
private enum SoapMessages
{
AuthenticationToken,
CreateAccount,
RemoveAccount,
Account
}

thanks in what I can help

German Gracia


hoanghoan
Posts: 1
Joined: Mon Apr 03, 2017 8:29 am

Re: consume service SOAP in c# error SSL

Postby hoanghoan » Mon Apr 03, 2017 8:33 am

ServicePointManager.ServerCertificateValidationCallback = (senderX, certificate, chain, sslPolicyErrors) => true; //fix SSL/TLS


WebResponse resp = request.GetResponse(); <- here occurs error --------------------- Unable to establish a relationship of trust secure channel for SSL / TLS, .

Return to “Developers”

Who is online

Users browsing this forum: No registered users and 4 guests