Reagrding WCF Service was created in the SharePoint

Frequent Contributor

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();
            }

 

0 Replies