none
Reagrding WCF Service was created in the SharePoint RRS feed

  • Question

  • Hi there,

    the question is weird. the code in the Console App (.NET Core 3.0) works properly, on the contrary, we used the same code in the .NET Standard 2.0, it turns out the following error message ::

    =============================================================================

    "[12:36:21 AM] [ERROR]  CallTecturaWebService: The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'NTLM'.
    [12:36:21 AM] [ERROR]  The remote server returned an error: (401) Unauthorized.
    [12:36:21 AM] [ERROR]     at System.Net.HttpWebRequest.GetResponse()
       at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)

    =============================================================================

    does anyone have any idea on it???

    my WCF web.config:

    <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior name="MyServiceBehavior">
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"></serviceMetadata>
              <serviceDebug includeExceptionDetailInFaults="true"></serviceDebug>
    		  <serviceCredentials>
    				<serviceCertificate findValue="extlab.litwareinc.pri" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName"/>
    		  </serviceCredentials>
    		</behavior>
          </serviceBehaviors>
          <endpointBehaviors>
            <behavior name="jsonBehaviour">
              <webHttp />
            </behavior>
          </endpointBehaviors>
        </behaviors>
        <bindings>
          <wsHttpBinding>
            <binding name="wsHttpsEndpointBinding" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647">
              <security mode="TransportWithMessageCredential">  
                    <!--<transport clientCredentialType="Ntlm" />--> 
    				<message clientCredentialType="Certificate" />           
              </security>   
            </binding>
          </wsHttpBinding>
        </bindings>
        <services>
          <service name="TecturaWsListItems.v2.Service" behaviorConfiguration="MyServiceBehavior">
            <endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHttpsEndpointBinding" contract="TecturaWsListItems.v2.IService" />
            <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange">
            </endpoint>
          </service>
        </services>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true">
        </serviceHostingEnvironment>
      </system.serviceModel>

    my code is :

    var myBinding = new WSHttpBinding();
                myBinding.Security.Mode = SecurityMode.TransportWithMessageCredential;
                myBinding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate;
                //myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
    
                var myEndPoint = new EndpointAddress("https://extlab.litwareinc.pri/_vti_bin/TecturaWsListItems.v2/service.svc");
    
                serviceClient.ServiceClient actionsClient = new serviceClient.ServiceClient(myBinding, myEndPoint);
    
                actionsClient.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName,
        "extlab.litwareinc.pri");
    
                string filename = @"C:\Windows\Temp\mat-debug-13252.log";
                //string filename = @"Z:\sharing\docs\disableloopback.txt";
    
                using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
                {
                    // Create a byte array of file stream length
                    byte[] bytes = System.IO.File.ReadAllBytes(filename);
    
                    //Read block of bytes from stream into the byte array
                    fs.Read(bytes, 0, System.Convert.ToInt32(fs.Length));
    
                    serviceClient.OutlookMailItem documentData = new serviceClient.OutlookMailItem();
                    documentData.Content = bytes;
                    documentData.DomainName = "outlook.com";
                    documentData.EmailAddress = "hilfiger1014@outlook.com";
                    documentData.FileLeafRef = Path.GetFileName(filename);
                    documentData.MailType = true;
    
                    actionsClient.UploadMSGToDocumentLibary(documentData);
    
                    Console.WriteLine(documentData.FileLeafRef + " has been uploaded.");
    
                    //Close the File Stream
                    fs.Close();
                }


    Hi there, if you found my comment very helpful then please | Propose as answer | . Thanks and Regards.

    Sunday, November 24, 2019 8:47 AM

All replies

  • Hi,
    As far as I know, neither the Asp.net Core project nor the .Net Stardard project, they are not compatible with wshttpbinding with certificate authentication.
    Besides, Regarding Authenticating the client with a certificate, please refer to the official document.
    https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/transport-security-with-certificate-authentication
    Best Regards
    Abrham
    Monday, November 25, 2019 2:22 AM
    Moderator
  • Hi Abraham,

    I follow the documentation (https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/transport-security-with-certificate-authentication) and I got the error as the following message:

    System.ServiceModel.Security.MessageSecurityException
      HResult=0x80131500
      Message=The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'NTLM'.
      Source=System.Private.ServiceModel
      StackTrace:
       at System.ServiceModel.Channels.HttpResponseMessageHelper.ValidateAuthentication()
       at System.ServiceModel.Channels.HttpResponseMessageHelper.<ParseIncomingResponse>d__7.MoveNext()
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at System.ServiceModel.Channels.HttpChannelFactory`1.HttpClientRequestChannel.HttpClientChannelAsyncRequest.<ReceiveReplyAsync>d__17.MoveNext()
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at System.ServiceModel.Channels.RequestChannel.<RequestAsync>d__33.MoveNext()
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at System.ServiceModel.Channels.RequestChannel.<RequestAsyncInternal>d__32.MoveNext()
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at System.Runtime.TaskHelpers.WaitForCompletionNoSpin[TResult](Task`1 task)
       at System.ServiceModel.Channels.RequestChannel.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, ProxyOperationRuntime 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 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Reflection.DispatchProxyGenerator.Invoke(Object[] args)
       at generatedProxy_1.UploadMSGToDocumentLibary(OutlookMailItem )
       at serviceClient.ServiceClient.UploadMSGToDocumentLibary(OutlookMailItem outlookMailItem) in C:\Users\msClient\source\repos\wcfSPdocument.client\Connected Services\serviceClient\Reference.cs:line 177
       at wcfSPdocument.client.Program.Main(String[] args) in C:\Users\msClient\source\repos\wcfSPdocument.client\Program.cs:line 79


    Hi there, if you found my comment very helpful then please | Propose as answer | . Thanks and Regards.

    Monday, November 25, 2019 2:48 AM
  • Hi,

    Export the server certificate to the client machine and install the certificate into Trusted Root Certification Authorities instead of Personal Certiifcate.
    https://i.stack.imgur.com/Qpkwk.png
    For verifying this, Access the service metadata page, there should be a flag of security lock in the browser address bar.
    https://i.stack.imgur.com/cMhwy.png
    Similarly, we need to install the certificate provided by the client on the server.

    Best Regards

    Abraham

     
    Monday, November 25, 2019 7:21 AM
    Moderator