The target principal name is incorrect Error when calling Rest Service

  • 17 August 2017
  • 2 replies
  • 228 views

Dear all,

 

in my asp.net  application, on ASPX page need consume K2 REST service using the code below:

 

private const string WORKLISTRESTURL = "http://myserver.domain.com:81/K2Services/REST.svc/Worklist/Items";

HttpWebRequest request = WebRequest.Create(WORKLISTRESTURL) as HttpWebRequest;
request.Credentials = CredentialCache.DefaultNetworkCredentials;
XDocument responseDocument;
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
using (Stream responseStream = response.GetResponseStream())
using (XmlReader responseReader = XmlReader.Create(responseStream))
{
responseDocument = XDocument.Load(responseReader);
}

 

When the code is executed, it return error:

 

Exception Details: System.ComponentModel.Win32Exception: The target principal name is incorrect

Source Error: 
 

Line 25:         // get response Line 26:         XDocument responseDocument; Line 27:         using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) Line 28:         using (Stream responseStream = response.GetResponseStream()) Line 29:         using (XmlReader responseReader = XmlReader.Create(responseStream)) 

 

While if I directly key in  "http://myserver.domain.com:81/K2Services/REST.svc/Worklist/Items" in browser, it can return data correctly.

 

What could be wrong with the server/development PC setting?

 

Thank and regards,

SH


2 replies

Userlevel 5
Badge +18

This may be related to Authentication.


 


When you browse to the web service via the browser, it is likely picking up and authenticating with your windows credentials.  How is authentication configured for your asp.net web application?  Is it using Windows Authentication also?

Hi Tin,

 

Yes. Windows authentication, and try both impersonate = true or false. 

 <system.web>

      <identity impersonate="true" />

      <authentication mode="Windows" />

 </system.web>

 

In K2 Server we have already enabled the REST service and turned on windows integrated authenticaiton.

 

According to Microsoft, https://msdn.microsoft.com/en-us/library/system.net.credentialcache.defaultcredentials.aspx:

 

To get the credentials as a NetworkCredential instance, use the DefaultNetworkCredentials property.

The supported values for authType are "NTLM", "Digest", "Kerberos", and "Negotiate". This method does not work for HTTP or FTP protocols.

 

Do you have advice on the setting?

 

Thanks.

SH

 

 

 

Reply