Spring.NET WebServiceExporter 和 MVC3

发布于 2024-12-07 23:51:09 字数 1543 浏览 2 评论 0原文

我试图获得一个与 MVC3 一起使用的简单 Spring.NET Web 服务,但是尽管没有错误,并且我可以从日志中看到 Spring 正在部署它,但我根本无法访问我的 Web 服务的正确 URL。

认为我已经正确地遵循了这个示例(Spring.NET 附带的)。我的不同之处在于我没有在我的服务上进行任何 AOP 编织。据我所知,它应该有效......但没有。

这是我的服务类(非常基本)

public interface IHelloService
{
    string SayHello();
}

public class HelloService : IHelloService
{
    public String SayHello()
    {
        return "Hello";
    }
}

这是我的配置,

<!-- Web services -->
<object id="HelloService" type="Munch.Service.Web.HelloService, Munch.Service"/>

<!-- Exports contact service (weaved or not) as a web service. -->
<object id="HelloWebService" type="Spring.Web.Services.WebServiceExporter, Spring.Web">
  <property name="TargetName" value="HelloService"/>
  <property name="Namespace" value="http://Munch.Service.Web/HelloService"/>
  <property name="Description" value="Hello Web Services"/>
  <property name="TypeAttributes">
    <list>
      <object type="System.Web.Script.Services.ScriptServiceAttribute, System.Web.Extensions"/>
    </list>
  </property>
</object>

我希望能够通过 http://localhost:8080/Munch/HelloWebService.asmx 但我尝试过的任何变体都没有带来乐趣。有没有办法找出已经部署了哪些 Web 服务(也许是一些调试页面)?

Spring 附带的示例确实可以工作(!),所以我知道可以在我的机器上获得一个工作的 Spring WS,我只是看不出哪里出了问题。

I'm trying to get a simple Spring.NET webservice working with MVC3 but although there are no errors, and I can see from the logs that Spring is deploying it, I can't htt the correct URL for my web service at all.

I think I've followed the example (that comes with Spring.NET) correctly. Mine differs in that I'm not doing any AOP weaving on my service. As far as I can tell, it should work.... but doesn't.

Here's my service class (very basic)

public interface IHelloService
{
    string SayHello();
}

public class HelloService : IHelloService
{
    public String SayHello()
    {
        return "Hello";
    }
}

And here's my config

<!-- Web services -->
<object id="HelloService" type="Munch.Service.Web.HelloService, Munch.Service"/>

<!-- Exports contact service (weaved or not) as a web service. -->
<object id="HelloWebService" type="Spring.Web.Services.WebServiceExporter, Spring.Web">
  <property name="TargetName" value="HelloService"/>
  <property name="Namespace" value="http://Munch.Service.Web/HelloService"/>
  <property name="Description" value="Hello Web Services"/>
  <property name="TypeAttributes">
    <list>
      <object type="System.Web.Script.Services.ScriptServiceAttribute, System.Web.Extensions"/>
    </list>
  </property>
</object>

I would expect to be able to access my web service at something like http://localhost:8080/Munch/HelloWebService.asmx but no joy with any of the variations I have tried. Is there a way to find out what web services have been deployed (some debug page perhaps)?

The example that comes with Spring does actually work(!) so I know it's possible to get a working Spring WS on my machine, I just can't see where I've gone wrong.

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

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

发布评论

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

评论(1

白日梦 2024-12-14 23:51:09

我能够在 spring.net 1.3.2 附带的 spring.net Spring.Mvc3QuickStart 中发布您的 HelloService

为了让它工作,我必须做这些事情:

  1. 将服务配置添加到 spring.net mvc 上下文
  2. 将所有 asmx 资源添加到 routes.IgnoreRoute
  3. 添加 Spring.Web.Services来自 Spring.Web 的 .WebServiceHandlerFactory,正如 bbaia 对您的问题发表评论一样

,我怀疑您忘记将所有 asmx 资源添加到routes.IgnoreRoute

分步

从 Spring.Net 1.3.2 附带的 Spring.Mvc3QuickStart 示例应用程序开始。

引用包含问题中的 HelloService 类的项目。

将文件 ~/Config/services.xml 添加到项目中,其中包含您的服务配置:

<object id="HelloService" type="Munch.Service.Web.HelloService, Munch.Service"/>

<object id="HelloWebService" type="Spring.Web.Services.WebServiceExporter, Spring.Web">
  <property name="TargetName" value="HelloService"/>
  <property name="Namespace" value="http://Munch.Service.Web/HelloService"/>
  <property name="Description" value="Hello Web Services"/>
  <property name="TypeAttributes">
    <list>
      <object type="System.Web.Script.Services.ScriptServiceAttribute, System.Web.Extensions"/>
    </list>
  </property>
</object>

在 Global.asax 中,添加

routes.IgnoreRoute("{resource}.asmx/{*pathInfo}");

注册路由。这将告诉 asp.net mvc 处理程序将请求单独留给 asmx 资源。

在 web.config 中,添加以下 http 处理程序:

<system.web>
  <!-- ... -->
  <httpHandlers>
    <add verb="*" path="*.asmx" type="Spring.Web.Services.WebServiceHandlerFactory, Spring.Web" />
  </httpHandlers>
  <!-- ... -->

在 web.config 中,将服务配置添加到 spring 上下文中:

<spring>
  <context>
    <resource uri="file://~/Config/controllers.xml" />
    <resource uri="file://~/Config/services.xml" />
  </context>
</spring>

从 Visual Studio 运行应用程序时,您应该能够在 http://localhost:12345/HelloWebService.asmx (将 12345 替换为您的开发端口)。

注释

我不熟悉 asp.net-mvc,因此可能有比我建议的更好的方法来配置它。

I was able to use to publish your HelloService in the spring.net Spring.Mvc3QuickStart that ships with spring.net 1.3.2.

These were the things I had to do to get it to work:

  1. Add the service configuration to the spring.net mvc context
  2. Add all asmx resources to routes.IgnoreRoute
  3. Add the Spring.Web.Services.WebServiceHandlerFactory from Spring.Web, as bbaia had commented on your question

I suspect you've forgotten to add all asmx resources to routes.IgnoreRoute.

Step-by-step

Start with the Spring.Mvc3QuickStart example application that ships with Spring.Net 1.3.2.

Reference the project that contains the HelloService class from your question.

Add a file ~/Config/services.xml to the project, containing your service configuration:

<object id="HelloService" type="Munch.Service.Web.HelloService, Munch.Service"/>

<object id="HelloWebService" type="Spring.Web.Services.WebServiceExporter, Spring.Web">
  <property name="TargetName" value="HelloService"/>
  <property name="Namespace" value="http://Munch.Service.Web/HelloService"/>
  <property name="Description" value="Hello Web Services"/>
  <property name="TypeAttributes">
    <list>
      <object type="System.Web.Script.Services.ScriptServiceAttribute, System.Web.Extensions"/>
    </list>
  </property>
</object>

In Global.asax, add

routes.IgnoreRoute("{resource}.asmx/{*pathInfo}");

to RegisterRoutes. This will tell the asp.net mvc handler to leave requests to asmx resources alone.

In web.config, add the following http handler:

<system.web>
  <!-- ... -->
  <httpHandlers>
    <add verb="*" path="*.asmx" type="Spring.Web.Services.WebServiceHandlerFactory, Spring.Web" />
  </httpHandlers>
  <!-- ... -->

In web.config, add your service configuration to the spring context:

<spring>
  <context>
    <resource uri="file://~/Config/controllers.xml" />
    <resource uri="file://~/Config/services.xml" />
  </context>
</spring>

When you run the application from Visual Studio, you should be able to view the service at http://localhost:12345/HelloWebService.asmx (replace 12345 with you dev port).

Notes

I'm unfamiliar with asp.net-mvc, so there might be better ways to configure it than I've suggested.

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