问题标签 [wcf-rest-contrib]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
10514 浏览

wcf - 自托管 WCF REST 服务和基本身份验证

我创建了一个自托管的 WCF REST 服务(带有一些来自 WCF REST Starter Kit Preview 2 的额外服务)。这一切都很好。

我现在正在尝试将基本身份验证添加到服务中。但是我在 WCF 堆栈中遇到了一些相当大的障碍,这阻止了我这样做。

似乎HttpListener(自托管的 WCF 服务在 WCF 堆栈的低级别内部使用)正在阻止我尝试WWW-Authenticate在自生成的401 Unauthorized响应中插入标头。为什么?

如果我忘记了这个WWW-Authenticate标头(微软似乎也这样做了),我可以让身份验证工作。但这就是问题所在。如果我不发回WWW-Authenticate标头,那么 Web 浏览器将不会显示其标准的“登录”对话框。用户只会面临一个401 Unauthorized错误页面,无法实际登录。

计算机和人类都应该可以访问 REST 服务(至少在 GET 请求级别上)。因此,我觉得 WCF REST 在这里不符合 REST 的基本部分。有人同意我的观点吗?

有没有人使用自托管的 WCF REST 服务获得基本身份验证?如果是这样,你是怎么做到的?

PS:显然,我打算使用不安全的基本身份验证的前提是我也会让 HTTPS/SSL 也为我的服务工作。但那是另一回事。

PPS:我已经尝试过 WCF REST Contrib ( http://wcfrestcontrib.codeplex.com/ ) 并且有完全相同的问题。看来此库尚未在自托管场景中进行测试。

谢谢。

0 投票
1 回答
1645 浏览

wcf - Why is my WCF Rest Service on IIS7 Authenticating TWICE?

Ok, if someone could shed some light on this for me, I would greatly appreciate it. So here we go. I had a rest service running fine the other day but after I accidentally overwrote the web.config all hell broke loose. I've spent the past day and a half trying to sort things out but I can't seem to figure out what is missing or misplaced.

So, I've designed this service around WCF Rest Contrib (http://wcfrestcontrib.codeplex.com)'s authentication process. Now, I can get this working fine on my localhost w/ the current web.config (minus the endpoint entry) but once I upload it to discountasp and select "basic authorization" in the ISS7 Manager, it appears that I'm getting authenticated twice! Once using my discount asp.net user/pass and then the next time using the application user/pass. Unfortunately I only provide one set of credentials and don't want to hard code my discountasp account info into the app. Like I said before, this worked fine a few days ago. Anyway. here is my web.config as it is now:

So, whenever I upload this and change the ISS setting to Basic Authentication, it looks like it is trying to use the default handler for authentication as if I try to enter my web app user/pass, I get an error screen which has the following detailed information about the moduel/handler

Detailed Error Information

Module: IIS Web Core
Notification: AuthenticateRequest
Handler: svc-ISAPI-2.0
Error Code: 0x80070005

Requested URL: http://www.mydomain.com:80/MyService.../MyService.svc
Physical Path: E:\web\xxxxxx\htdocs\MyServiceBaseAddress\MyService.svc
Logon Method: Not yet determined
Logon User: Not yet determined

Now for the fun stuff... i tried providing my discountasp.net account username/password for kicks and sure enough it responded properly for any [OperationContract] which doesn't have [OperationAuthentication] defined (which is only one or two of the operations I have).

I thought this was strange, so I looked at fiddler and saw something interesting.

Whenever I try request a procedure with [OperationAuthentication] defined and provide my discountasp.net username/pass I get two different "WWW-Authenticate" headers back in Fiddler:

WWW-Authenticate: Basic realm="MyRESTServiceRealm"

WWW-Authenticate: Basic realm="www.mydomain.com"

On the other hand, if I try to access the same procedures with only my application's user/pass, I only get the site's header:

WWW-Authenticate: Basic realm="www.mydomain.com"

My hypothesis is that for some reason I'm having to pass through the default "Basic Authorization" layer set by IIS before I can get to the application's "Custom Basic Authorization" layer.

After verifying this by created an identical user/pass for my service that I use for my discountasp.net account, I was able to successfully pass both layers of authentication without any issues... so I think I can conclude that this is indeed the issue. Now how do I disable the default one? Do I need to do this in the IIS Manager, or in the web.config?

Anyway, I have absolutely no idea how this is possible or what I need to do to resolve the issue, but I know that something is seriously out of whack.

Any suggestions would be greatly appreciated! Thanks.

0 投票
0 回答
2138 浏览

c# - WcfRestContrib:是否有任何从桌面客户端使用 WCF REST 服务(具有基本身份验证)的示例

是否有任何使用 WCF REST 服务和来自桌面客户端的基本 HTTP 身份验证的示例?我正在使用 WCF REST Contrib。当从浏览器使用 javascript 客户端时,身份验证工作正常,但当我尝试使用 C# 控制台应用程序时。我收到BasicUnauthorizedException {“您尝试访问安全资源失败。”}。即使我提供了正确的用户名和密码。

任何帮助将不胜感激。

0 投票
1 回答
3185 浏览

c# - 以编程方式创建 WCF REST 客户端代理(在 C# 中)

我正在尝试使用以下代码在 C# 中以编程方式创建 REST 客户端代理,但我不断收到 CommunicationException 错误。我错过了什么吗?

这样我就可以按如下方式使用它:

0 投票
1 回答
1016 浏览

android - 使用 WCF/RESTful 服务的 Android 应用程序

我有一个基于WcfRestContrib 编写并托管在 iis7.5 中的 WCF RESTful 应用程序,它将 pdf 作为字节 [] 传递。我试图弄清楚如何以及最好的方法是在 Android 应用程序中使用此服务。我相信我处理了所有 Java/WCF 互操作问题,因为该服务由使用 java 的外部公司使用。但我没有看到很多例子。我已经读到我将不得不制作一个传递 JSON 而不是 XML 的方法,但否则我相信它应该可用于 Android 应用程序。我没有看到太多使用 RESTful 服务的 Android 应用程序示例,这不是 Android 的首选方法吗?

我看过几篇文章(http://romenlaw.blogspot.com/2008/08/sumption-web-services-from-android.html),但大多数看起来有点旧,尽管它们仍然可能有用。我只是好奇那里的任何专家会建议我如何处理这样的项目,如果需要,我可以创建另一种服务。我只是希望能够根据一些参数从服务中加载 pdf。安全是一个问题,但在这个阶段不是强制性的。服务当前使用基本身份验证并且在 https 上。

有什么想法吗?建议?

0 投票
1 回答
738 浏览

c# - 使用 WebAuthenticationConfiguration 时启用 401 质询响应

我有一个非常简单的 WCF4 Restful Web 服务,它使用 WcfRestContrib 来允许自定义基本身份验证。当客户端抢先提供用户名和密码时效果很好,但如果它们不返回 400 Bad Request 响应,而不是要求客户端提供凭据(通过 401 响应)。

该服务使用声明性方法通过使用属性装饰必要的类来实现 WcfRestContrib。这是我的 ServiceContract 声明:

它只有一个非常简单的操作:

我的UserNamePasswordValidator样子(尽管它可能无关紧要,因为它仅在传递凭据时才被调用):

我尝试调试 WcfRestContrib 并发现WebBasicAuthenticationHandler该类正在抛出一个BasicAuthorizationException(仅在框架代码中捕获),但是,由于某种原因,它没有将异常转换为 401。

根据我在WcfRestContrib github 站点上阅读的内容,其作者 (Mike O'Brian) 发布了一个问题,他说他希望看到它返回除 401 之外的任何内容,因为它当前返回401挑战。

如果有这个功能,那么我错过了什么,或者我做错了什么?

更新

如果无法使用 WcfRestContrib 执行此操作,是否有其他方法可以实现此目的(除了在 IIS 中使用标准的基于 Windows 的基本身份验证)?我对任何(其他)替代解决方案持开放态度。

0 投票
0 回答
425 浏览

c# - 如何使用 Windows 身份验证使用 wcf 休息服务

我正在为 WCF Rest 服务使用 webHttpbinding 配置。

我在下面指定了端点行为

在 IIS 中托管此服务后,如何在客户端使用此服务?

目前,我们在尝试通过以下方式在客户端访问它时遇到错误

错误:

此外,我们无法将其添加为客户端项目中的服务参考。

如果对此有任何想法,请分享您的想法。

0 投票
1 回答
222 浏览

rest - 通过 JSON 读取请求消息正文时出错

我需要从 WCF REST 服务中的请求正文中读取消息内容,例如 -

服务端代码

但是无论我尝试什么,我都会在服务方面遇到错误:

期待来自命名空间“http://schemas.microsoft.com/2003/10/Serialization/”的元素“base64Binary”。遇到名称为“人类”、命名空间“http://numans.hr-xml.org”的“元素” /2007-04-15'。

服务合同定义为:

实现如下:

客户端代码

我发送的内容是:

我尝试了许多选项来从客户端发送数据,例如:

并且还尝试了这个:

发帖要求:

我还尝试在客户端/服务器端进行序列化/反序列化,但这也不起作用。

有人可以建议我可以尝试的代码示例吗?或者指出我做错了什么。

我尝试使用 JSON 数据的更多示例:

为了清楚起见,粘贴我的客户端功能: