Invalid URI: The format of the URI could not be determined. on calling WCF service on .NET 6
- Dominant language
- C#
- Stars
- 1.8k
- Forks
- 576
- Avg merge
- 6d 9h
- Merged PRs (30d)
- 2
Description
**Describe the bug**
We have a code base that is on .NET Core 3.1 and we are upgrading it to .NET 6. The code has a call to WCF service that works fine on .NET Core 3.1, but starts throwing the below error after upgrade to .NET 6:
```
Exception: System UriFormatException: Invalid URI: The format of the URI could not be determined.
at System.Uri. CreateThis(String uri, Boolean dontEscape. UriKind uriKind, UricreationOptions& creationOptions)
at System. Uri..ctor(String uriString)
at System.Xml.xmlResolver.ResolveUri(Uri baseUri, String relativeUri)
at System.Xml.XmlTextReaderImpl.ConvertAbsoluteUnixPathToAbsoluteUri (Strings url, xmlResolver resolver)
at System.Xml.XmlTextReaderImpl..ctor(Stream stream, Byte[] bytes, Int32 byteCount, XmlReaderSettings settings, Uri baseUri, String baseUriStr, XmlParserContext context, Boolean closeInput)
at System.Xml.xmlReaderSettings. CreateReader (Stream input, Uri baseUri, String baseUriString, XmlParserContext inputContext)
at System.Xml.XmlReader.Create(Stream input, XmlReaderSettings settings, String baseUri)
at System.Security.Cryptography.xml.Utils.PreProcessStreamInput (Stream InputStream, XmlResolver xmlResolver, String baseUri)
at System.Security.Cryptography.Xml.ExcCanonicalxml..ctor(Stream inputStream, Boolean includeComments, String inclusiveNamespacesPrefixList, XmlResolver resolver, String strBaseUri)
at System.Security.Cryptography.Xml.XmlDsigExcC14NTransform.LoadInput(Object obj)
at System.Security.Cryptography.Xml.TransformChain. TransformToOctetStream(Object InputObject, Type inputType, XmlResolver resolver, String baseUri)
at System.Security.Cryptography.Xml.TransformChain. TransformToOctetStream(Stream Input, XmlResolver resolver, String baseUri)
at System.Security.Cryptography.Xml.Reference.CalculateHashValue(XmlDocument document, CanonicalXmlNodeList refList)
at System Security.Cryptography.Xml.Reference.UpdateHashValue(XmlDocument document, CanonicalXmlNodeList refList)
at System.Security.Cryptography.Xml.SignedXml.BuildDigestedReferences()
at System.Security.Cryptography.Xml.SignedXml.ComputeSignature()
at System.ServiceModel.Security.WSSecurityOneDotZeroSendSecurityHeader.CompletePrimarySignatureCore (SendSecurityHeaderElement[] signatureconfirmations, SecurityToken[] signedEndorsingTokens, SecurityToken[] signedTokens, SendSecurityHeaderElement[] basicTokens, Boolean isPrimarySignature)
at System.ServiceModel.Security.WSSecurityOneDotZeroSendSecurityHeader.CreateSupportingSignature(SecurityToken token, SecurityKeyIdentifier identifier)
at System.ServiceModel.Security.SendSecurityHeader.SignwithSupportingToken(SecurityToken token, SecurityKeyIdentifierClause identifierClause)
at System.ServiceModel.Security.SendSecurityHeader.SignwithSupportingTokens()
at System.ServiceModel.Security.SendSecurityHeader.CompleteSecurityApplication()
at System.ServiceModel.Security.SecurityAppliedMessage.OnWriteMessage(XmlDictionaryWriter writer)
at System.ServiceModel.Channels.Message.WriteMessage(XmlDictionaryWriter writer)
at System.ServiceModel.Channels.BufferedMessagewriter.WriteMessage(Message message, BufferManager bufferManager, Int32 initialoffset, Int32 maxSizeQuota)
at System.ServiceModel.Channels.TextMessageEncoderFactory. TextMessageEncoder.WriteMessageAsync(Message message, Int32 maxMessageSize, BufferManager bufferManager, Int32 messageOffset)
at System.ServiceModel.Channels.TextMessageEncoderFactory.TextMessageEncoder.WriteMessage(Message message, Int32 maxMessageSize, BufferManager bufferManager, Int32 messageOffset)
at System.ServiceModel.Channels.MessageEncoder.WriteMessage(Message message, Int32 maxMessageSize, BufferManager bufferManager)
at System.ServiceModel.Channels.BufferedMessageContent.EnsureMessageEncoded()
at System.ServiceModel.Channels.BufferedMessageContent.TryComputeLength (Int64& length)
at System.Net.Http.HttpContent.GetComputedOrBufferLength()
at System.Net.Http.Headers.HttpContentHeaders.get_ContentLength()
at System.Net.Http.SocketsHttpHandler.ValidateAndNormalizeRequest(HttpRequestMessage request)
at System.Net.Http.SocketsHttpHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClientHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClientHandler SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpMessageInvoker. SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.<>n__0(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpClientRequestChannel.HttpClientChannelAsyncRequest.SendRequestAsync(Message message, TimeoutHelper timeoutHelper)
at System.ServiceModel.Channels.RequestChannel.RequestAsync(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.RequestAsyncInternal (Message message, TimeSpan timeout)
at System.Runtime.TaskHelpers.ToApmEnd[TResult](IAsyncResult iar)
at System.ServiceModel.Channels.RequestChannel.EndRequest (IAsyncResult result)
at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic (IAsyncResult iar, Func`2 endfunction, Action`1 endAction, Task` 1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location ---
at System.ServiceModel.Channels.SecurityChannelFactory`1. SecurityRequestChannel.RequestAsync(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.RequestAsyncInternal(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.Request (Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder Request (Message message, TimeSpan timeout)
at System.Servicemodel.Channels.ServiceChannel.call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] Ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.call(String action, Boolean oneway, ProxyOperationuntime operation, Object[] ins, Object[] outs)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(MethodCall methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(MethodInfo targetMethod, Object[] args)
at generatedProxy_1.GetCustomerInfo(CustomerInfoRequest )
at CustomerService.CustomerServiceClient.GetCustomerInfo(CustomerInfoRequest customerInfoRequest) in D:\apps\jenkins\workspace\Jenkins-build281-902370858199\src\Connected Services\CustomerService\Reference.cs:line 4442
```
This is the binding we use:
```csharp
services.AddSingleton(s =>
{
TextMessageEncodingBindingElement encoding= new TextMessageEncodingBindingElement();
encoding.WriteEncoding = System.Text.Encoding.UTF8;
var binding new BasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential);
binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.Certificate;
var customBinding = new CustomBinding(binding);
var sbe = customBinding.Elements.Find();
var httpsTransport = new HttpsTransportBindingElement();
httpsTransport.MaxBufferSize = 2000000000;
httpsTransport.MaxReceivedMessageSize=2000000000;
httpsTransport.MaxBufferPoolSize=2000000000;
var dvsBinding = new CustomBinding(sbe, encoding, httpsTransport);
dvsBinding.OpenTimeout new TimeSpan (0, 10, 0);
dvsBinding.CloseTimeout = new TimeSpan (0, 10, 0);
dvsBinding.SendTimeout = new TimeSpan (0, 10, 0);
dvsBinding.ReceiveTimeout = new TimeSpan (0, 10, 0);
EndpointAddress endpointAddress = new EndpointAddress(serviceConfig.CustomerServiceUrl);
X509Certificate2 certificate = new X509Certificate2(serviceConfig.TrustStore, serviceConfig.CertPassword);
var client = new CustomerServiceClient(dvsBinding, endpointAddress);
client.ClientCredentials.ClientCertificate.Certificate = certificate;
return client;
});
```
The application is deployed on a Kubernetes pod running alpine Linux.
Looking at the call stack, it seems like it's trying to sign an XML, but is running into some problems with the URI. But I cannot make out what URI is expected.
Not sure if this error is strictly a WCF issue, but would really like to know what is being signed and what could be the reason for the Invalid URI exception, as nothing in the code is changed except the .NET 6 upgrade.
**To Reproduce**
Steps to reproduce the behavior:
1. Create a WCF client in .NET 6 with the above bindings, deploy to Kubernetes running Alpine Linux
Any help on this issue is appreciated.
Thanks!
Contributor guide
Assessment
This issue has not been assessed yet.