I’m trying to reach a 3th party API with an asp.net core (C#) app. I get stuck on the connection already. The owners of the API don ‘t know much about C# and can’t help much. For test purposes I wrote the code directly in the Homecontroller ‘s index method.
public IActionResult Index()
{
// create an instance of the binding
BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
binding.MaxReceivedMessageSize = int.MaxValue;
binding.Security.Mode = (BasicHttpSecurityMode)SecurityMode.Transport;
try
{
using (var client = new V3PortClient(binding, new EndpointAddress(new Uri("https://platform.com/Webservices/V3?wsdl"))))
{
//Sent a message in the platform
var result = client.sendMsgAsync(accesscode, userIdentifier, title, body, senderIdentifier, 0, 0, false);
ViewBag.Message = result.Result;
}
}
catch (Exception ex)
{
// handle exception
ViewBag.Message = ex;
}
return View();
}
This code gives this error on the closing bracket of “using (var client = new V3PortClient…”
System.ServiceModel.CommunicationObjectFaultedException: The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state. at System.ServiceModel.Channels.CommunicationObject.System.ServiceModel.IAsyncCommunicationObject.CloseAsync(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.CloseAsyncInternal(TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannelProxy.System.ServiceModel.ICommunicationObject.Close(TimeSpan timeout) at System.ServiceModel.ClientBase`1.System.ServiceModel.ICommunicationObject.Close(TimeSpan timeout) I have this in an Reference class (it’s a part from the class) public V3PortClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : base(binding, remoteAddress)
I’m almost sure the password (accesscode) doesn’t have to be included in the binding because it’s been asked for every time a task is being started see below ‘sendMsgAsync(string accesscode,…”
[System.ServiceModel.OperationContractAttribute(Action="https://platform.com/Webservices/V3#sendMsg", ReplyAction="*")]
[System.ServiceModel.XmlSerializerFormatAttribute(Style=System.ServiceModel.OperationFormatStyle.Rpc, SupportFaults=true, Use=System.ServiceModel.OperationFormatUse.Encoded)]
[return: System.ServiceModel.MessageParameterAttribute(Name="return")]
System.Threading.Tasks.Task<object> sendMsgAsync(string accesscode, string userIdentifier, string title, string body, string senderIdentifier, object attachments, int coaccount, bool copyToLVS);
I am on completely new ground here so any help will be appreciated.
Thanks in advance