未配置(但工作)的端点会产生什么后果?

发布于 2024-09-26 21:38:04 字数 618 浏览 0 评论 0原文

我有一个功能齐全的 wcf 服务,我可以在客户端上使用 jQuery 执行 CRUD 操作。我希望这个小型服务应用程序是可移植的,因此我试图避免任何应用程序或 web.config 设置(例如特定地址端点)。我已将我的服务应用程序编译成一个小的 dll 文件,并在托管于不同网址的几个不同项目中进行了尝试。一切正常。

我在 web.config 文件中放入的唯一设置是 aspNetCompatibilityEnabled,因为我使用的是表单身份验证。我没有为我的服务合同定义名称或命名空间,并且我的 app.config 文件是空的,没有连接字符串。当我输入 .svc 文件的地址时,我收到“未找到端点错误”。但是,当我使用我在操作合同中定义的 UriTemplates 时,我的服务可以正常运行。这会产生什么后果?

我不关心在 .svc 文件上公开我的数据对象或方法。我只需要这项服务是可移植的,并且不会由于一些不可预见的错误而崩溃。

谨慎乐观。

更新 经过进一步调查,我上面的示例似乎是 WCF 的默认行为。 MS 有一篇很好的文章在此处进行了解释。

I have a fully functional wcf service where I can perform CRUD operations using jQuery on the client. I want this small service application to be portable so I am trying to avoid any app or web.config settings (e.g. Specific address endpoints). I have compiled my service application into a small dll file and have tried it in several different projects hosted at various web addresses. Everything works fine.

The only setting I put in the web.config file was for aspNetCompatibilityEnabled because I am using forms authentication. I did not define a name or a namespace for my service contract and my app.config file is empty sans a connectionstring. When I type in the address to my .svc file I get the 'endpoint not found error'. However my service is fully functional when I use the UriTemplates I defined in my operation contracts. What are the ramifications of this?

I don't care about exposing my data objects or methods on the .svc file. I just need this service to be portable and not blow up due to some unforeseen error.

Cautiously optimistic.

UPDATE
After further investigation it appears my example above is the default behavior for WCF. There is a good article from MS that explains it here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绮烟 2024-10-03 21:38:04

我不确定你所说的便携式是什么意思。您的服务位于 dll 中,可以在任何 Web 应用程序中使用。那么这取决于您的.NET Framework 版本。

在 .NET 3.5 中,您必须在 .svc 文件中托管服务,并在配置文件或代码中配置它(服务、端点、行为、AspNetCompatibility)。

在 .NET 4.0 中,您可以利用简单的配置模型,该模型可以根据其他提供的信息为您创建端点。您可以通过基于配置的激活或服务路由将服务托管在 .svc 文件中。在所有情况下,使用 WebServiceHostFactory 来允许使用 WebHttpBinding 自动创建端点非常重要。您只需要配置AspNetCompatibility。如果您需要进一步指定 webHttp 行为,您也可以将其放置在配置中,而不指定行为的名称。此类行为将被视为所有服务的默认行为(在 .NET 3.5 中也是不可能的)。

在这两种情况下,您都不需要配置基地址,因为它始终取自托管 Web 应用程序。

I'm not sure what do you mean by portable. Your service is in dll, which can be used in any web application. Then it depends on your version of .NET Framework.

In .NET 3.5 you have to host the service in .svc file and configure it (service, endpoints, behaviors, AspNetCompatibility) in configuration file or in code.

In .NET 4.0 you can take advantage of simplyfied configuration model which can create endpoints for you based on other provided information. You can host the service in .svc file, by configuration based activation or by service route. In all cases it is important to use WebServiceHostFactory to allow automatic creation of endpoint using WebHttpBinding. You only need to configure AspNetCompatibility. If you need to futher specify webHttp behavior you can place it also in configuration without specifying behavior's name. Such behavior will be taken as default for all services (also not possible in .NET 3.5).

In neither case you don't need to configure base address because it is always taken from hosting web application.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文