假设我有一个 ASP.net Web 服务。带有 *.asmx-Files 的旧版本。在 IIS 8 上运行
当我尝试使用 WCF 服务客户端在 Visual Studio 中通过“添加服务引用”访问它时,它不起作用。
我的问题是“基本 HTTP 身份验证”..
错误信息
{"Die HTTP-Anforderung ist beim Clientauthentifizierungsschema \"Anonymous\" nicht autorisiert. Vom Server wurde der Authentifizierungsheader \"Basic Realm=\"WebsitePanel Enterprise Server\"\" empfangen."}
已翻译
{"The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Basic realm=\"WebsitePanel Enterprise Server\"'"}
当我使用“网络引用”时,它确实有效。 [我正在使用 WebsitePanel 并尝试访问其企业服务器 Web 服务(asmx 文件)]
是否可以将旧的 ASMX-Web 服务与“WCF 服务引用”-Clients 一起使用? 有人可以解释差异,我应该使用什么吗?
最佳答案
根据对您问题的评论,我假设您忘记提供一些身份验证信息。通过在代理对象中提供有效的用户名和密码,您应该能够调用该服务:
client.ClientCredentials.UserName.UserName = "foo";
client.ClientCredentials.UserName.Password = "bar";
client.SomeMethod();
此外,您应该确保将配置设置为 Transport
(或 TransportCredentialOnly
和 clientCredentialType="Basic"
):
<bindings>
<basicHttpBinding>
<binding name="myBinding">
<security mode="Transport">
<transport clientCredentialType="Basic" proxyCredentialType="None" realm="WebsitePanel Enterprise Server" />
</security>
</binding>
</basicHttpBinding>
</bindings>
要获取更详细的错误信息,请配置跟踪:http://msdn.microsoft.com/en-us/library/ms733025%28v=vs.110%29.aspx
关于c# - ASP.net Webservice *.asmx 访问与 WCF 服务引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27767142/