Spring.NET WebServiceExporter 和 MVC3
我试图获得一个与 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能够在 spring.net 1.3.2 附带的 spring.net
Spring.Mvc3QuickStart
中发布您的HelloService
。为了让它工作,我必须做这些事情:
routes.IgnoreRoute
Spring.Web.Services来自
,正如 bbaia 对您的问题发表评论一样Spring.Web
的 .WebServiceHandlerFactory,我怀疑您忘记将所有 asmx 资源添加到
routes.IgnoreRoute
。分步
从 Spring.Net 1.3.2 附带的 Spring.Mvc3QuickStart 示例应用程序开始。
引用包含问题中的
HelloService
类的项目。将文件
~/Config/services.xml
添加到项目中,其中包含您的服务配置:在 Global.asax 中,添加
到
注册路由
。这将告诉 asp.net mvc 处理程序将请求单独留给 asmx 资源。在 web.config 中,添加以下 http 处理程序:
在 web.config 中,将服务配置添加到 spring 上下文中:
从 Visual Studio 运行应用程序时,您应该能够在 http://localhost:12345/HelloWebService.asmx (将 12345 替换为您的开发端口)。
注释
我不熟悉 asp.net-mvc,因此可能有比我建议的更好的方法来配置它。
I was able to use to publish your
HelloService
in the spring.netSpring.Mvc3QuickStart
that ships with spring.net 1.3.2.These were the things I had to do to get it to work:
routes.IgnoreRoute
Spring.Web.Services.WebServiceHandlerFactory
fromSpring.Web
, as bbaia had commented on your questionI 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:In Global.asax, add
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:
In web.config, add your service configuration to the spring context:
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.