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:49 AM

All replies

  • Hi

    Do you mean same code works in Console APP for core 3.0 but not console app in .NET 2.0?

    Maybe the .net libraries are different or the build&deployment options are different.


    Justin Liu Office Apps & Services MVP, MCSE
    Senior Software Engineer
    Learn Microsoft 365 from Microsoft DOCs now!
    Please Vote and Mark as Answer if it helps you.

    Monday, November 25, 2019 5:41 AM
  • Hi Will,

    From the error message:

    The authentication header received from the server was 'NTLM'.

    It specified the authentication in SharePoint Server is NTLM and if you want to upload a file into SharePoint library, suggest to use CSOM like below, pass NTLM user credential with NetWorkCredential:

    using (ClientContext clientContext = new ClientContext("https://extlab.litwareinc.pri/sites/dev"))
    {
    	clientContext.Credentials = new NetworkCredential("username", "pwd","Domain");
    	clientContext.AuthenticationMode = ClientAuthenticationMode.Default;
    	string filepath = @"C:\Windows\Temp\mat-debug-13252.log";
    	clientContext.ExecuteQuery();
    
    	using (FileStream fs = new FileStream(filepath, FileMode.Open))
    	{
    		Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, "/sites/dev/Shared Documents/" + System.IO.Path.GetFileName(filepath), fs, true);
    	}
    
    }

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Thursday, November 28, 2019 9:23 AM