ich einen einfachen WCF-Dienst erstellen [Service]Der Remote-Server hat einen Fehler zurückgegeben: (401) Nicht autorisiert. wcf httpbinding Grund
public interface IService1
{
[OperationContract]
[WebInvoke(Method = "GET", UriTemplate = "/Data/{data}")]
string GetData(string data);
}
Mit diesem kundenspezifischen Auth-Validierung:
public class userpass : UserNamePasswordValidator
{
public override void Validate(string userName, string password)
{
if (string.Equals(userName, "1", StringComparison.OrdinalIgnoreCase)
&& password == "1")
return;
throw new SecurityTokenValidationException();
}
}
Und dieses webconfig:
<bindings >
<webHttpBinding>
<binding>
<security mode="Transport">
<transport clientCredentialType="Basic"/>
</security>
</binding>
</webHttpBinding>
</bindings>
Und
Und der Client-Code:
Uri reqUri = new Uri("https://union-pc58.union.com/Service1.svc/data/asdsad");
WebRequest req = WebRequest.Create(reqUri);
req.PreAuthenticate = true;
NetworkCredential credential = new NetworkCredential("1", "1");
req.Credentials = credential;
WebResponse resp = req.GetResponse();
DataContractSerializer data = new DataContractSerializer(typeof(string));
var res = data.ReadObject(resp.GetResponseStream());
Console.WriteLine(res);
Aber wenn ich den Client-Code ausführen bekomme ich diesen Fehler: Statt
An unhandled exception of type 'System.Net.WebException' occurred in System.dll
Additional information: The remote server returned an error: (401) Unauthorized.
es interne Fehler 500 –
kehrte ich die Standardauthentifizierung verwenden, weil ich keine Lösung für meine Frage finden Sie hier: https: //stackoverflow.com/questions/45767892/customauthorizationpolicy-evaluate-method-never-feuert-in-wcf-webhttpbinding –
Fehler 500 bedeutet normalerweise, dass etwas mit Ihrer API nicht funktioniert - https://Stackoverflow.com/a/18713917/6266562 –