JAX-WS Web服务 - 将String中输入XML的一部分获取到字段中(JAX-WS web service - Get portion of input XML in String to a field)
我有一个Java类,其方法是作为webservice方法公开的。 下面是我的Java类。
@WebService public class TestService{ public String testMethod(InputVO input) { } } public class InputVO{ private Data data; } public class Data{ private String xmlData; }
现在在我的InputVO中,我有一个Data字段,它有一个String xmlData。
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:svc="http://test.svc.com/"> <soapenv:Header/> <soapenv:Body> <svc:testMethod> <arg0> <data> <!-- ANY XML CONTENT--> </data> </arg0> </svc:service> </soapenv:Body> </soapenv:Envelope>
这是我的服务期望的输入XML文件的结构。 在数据元素内部,我应该能够传递任何XML内容。 现在在我的服务的
testMethod
,我应该在XML格式的Data
对象的xmlData
元素中获取这些数据。 我已经为我的wsdl的xsd文件中的内容设置了内容。<xs:complexType name="data"> <xs:sequence> <xs:any/> </xs:sequence> </xs:complexType>
但是当我在
InputVO
检查我的xmlData
字段时,它将InputVO
null。 如何将完整的String XML数据设置为xmlData
字段? 请帮助我。I have a Java class with a method exposed as a webservice method. Below is my Java class.
@WebService public class TestService{ public String testMethod(InputVO input) { } } public class InputVO{ private Data data; } public class Data{ private String xmlData; }
Now in my InputVO, I've a Data field which has a String xmlData.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:svc="http://test.svc.com/"> <soapenv:Header/> <soapenv:Body> <svc:testMethod> <arg0> <data> <!-- ANY XML CONTENT--> </data> </arg0> </svc:service> </soapenv:Body> </soapenv:Envelope>
This is the structure of the Input XML file that my service expects. Inside the data element, I should be able to pass any XML content. Now in my service's
testMethod
, I should get this data in the XML format inxmlData
element ofData
object. I've set for the content inside data in the xsd file of my wsdl.<xs:complexType name="data"> <xs:sequence> <xs:any/> </xs:sequence> </xs:complexType>
But when I check my
xmlData
field inInputVO
, it is coming as null. How do I set the complete String XML data intoxmlData
field? Kindly help me.
原文:https://stackoverflow.com/questions/19935528
最满意答案
您必须通过将动态语言值传递给控制器来单独映射每个路由。 例如:
routes.MapRoute( name: "News English", url: "News", defaults: new { controller = "Home", action = "News", language = "en-US"} ); routes.MapRoute( name: "News Italian", url: "Notizie", defaults: new { controller = "Home", action = "News", language = "it-IT" } );
在你的控制器中,你可以获得语言,并用它做你想做的事情(例如设置当前的文化和当前的UI文化):
public ActionResult News(string language) { System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(language); System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(language); //Do what you want return View(); }
You have to map each route individually by passing a dynamic language value to the controller. For example:
routes.MapRoute( name: "News English", url: "News", defaults: new { controller = "Home", action = "News", language = "en-US"} ); routes.MapRoute( name: "News Italian", url: "Notizie", defaults: new { controller = "Home", action = "News", language = "it-IT" } );
and in your controller you can get the language and do what you want with it (for example set the current culture and current UI culture):
public ActionResult News(string language) { System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(language); System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(language); //Do what you want return View(); }
相关问答
更多-
为什么MapRoute搞砸了?(Why is MapRoute messing up?)[2022-05-17]
以下是用户WeTTTT粘贴的正确答案。 我相信你的网站根目录下有一个“课程”文件夹,这会导致网址根本没有打到mvc路由。 解决此问题的一种快速方法是添加routes.RouteExistingFiles = true;,但这不是建议的,可能会导致其他问题。 您是否希望/允许将“课程”文件夹名称更改为绕过路由的其他内容? - WeTTTT 3月21日12:11 The following is pasted from user WeTTTT as was the correct answer. I belie ... -
如果您在ASP.NET之上使用Web API,它们最终将在相同的底层ASP.NET路由表上运行 - 但正如从用户角度指出的那样,您可以通过两种不同的方法来注册路由。 路由是这样设计的,因此当ASP.NET外部托管时,Web API不必依赖于System.Web。 请记住,Web API不是坐在MVC,Web窗体之上,或者是ASP.NET。 它可以在Web上下文(ASP.NET)中托管,但也可以是自托管(Console,WPF等),甚至托管在内存中(无端口使用,即轻量级的端到端测试)。 If you use ...
-
MapRoute只是一个更广义的Route.Add()的包装它是一个确切的扩展方法。 路由不是特定于MVC,因此允许您提供任何合适的路由。 这使得它非常灵活,并允许您实现自己的自定义RouteHandlers。 我在ASP.Net 3.5中为.aspx页面做了这个。 它看起来像这样: routes.Add("Blah", Route("custom/{stuff}", new SecretSauceRouteHandler())) MapRoute is just a wrapper around ...
-
您必须通过将动态语言值传递给控制器来单独映射每个路由。 例如: routes.MapRoute( name: "News English", url: "News", defaults: new { controller = "Home", action = "News", language = "en-US"} ); routes.MapRoute( name: ...
-
MapRoute未按预期工作(MapRoute not working as expected)[2023-12-22]
鉴于您提供的信息,我认为这两条路线都不符合要求。 MVC将寻找带有“id”参数的方法签名,并且您的操作方法没有。 如果请求实际上将您带到Home控制器上的Index方法,请检查某处的错误处理程序是否正在捕获该条件,然后将您重定向到/ Home / Index 如果按如下方式设置路由表,则第一个路由将根据需要进行匹配。 public static void RegisterRoutes(RouteCollection routes) { routes.MapRoute( name: "Ho ... -
.Net核心多语言路由(.Net Core Multi-Language Routing)[2022-07-08]
它比表面变化更深。 找到了达米安博德对这个话题的参考, https://damienbod.com/2015/10/21/asp-net-5-mvc-6-localization/ https://github.com/damienbod/AspNet5Localization/tree/master/src/AspNetCoreLocalization 来源和他写的话题。 在解释中,它确实涉及与他展示的webapi相关的ActionFilter。 我认为它是你的一个起点。 Great news, fina ... -
实际上,我没有得到你要求的内容,但通过查看代码,这不是在MVC 3,4和5中创建/使用Areas的标准方式。 您不需要在每个控制器内写入逻辑并执行重定向。 在我的RouteConfig ,我通常只有默认的路由映射。 当你需要区域时,你可以在Visual Studio中右键点击MVC web项目,然后点击'添加 - >区域'。 这将在Web项目的根目录下的Areas文件夹内创建一个带有区域名称的文件夹。 在区域文件夹内,您应该找到区域名称和映射的AreaRegistration.cs 。 public cla ...
-
MapRoute用于重载Action(MapRoute for overload Action)[2022-06-05]
首先,如果您使用相同的Http Verb(在您的情况下为GET),则不能重载控制器操作,因为您需要具有唯一的操作名称。 所以你需要以不同的方式命名你的行为: public class ProfileController : Controller { public ActionResult IndexKey( long? userkey ) { ... } public ActionResult IndexName( string username ) ... -
MVC 3如何使用MapRoute(MVC 3 How to use MapRoute)[2023-03-31]
你想配置你的问题的第一部分的路线是: routes.MapRoute( "", "home/default.aspx", new { controller = "Home", action = "Default" } ); 假设你想用某种参数'浏览'default.aspx,你可以这样做: routes.MapRoute( "", "home/default.aspx/{param}", new { controller = "Home", action ... -
因为当您请求yourBaseUrl/Process/ ,它匹配路由模式{controller}/{action}/{id} ,这是您定义的第一个路由的url模式(名为Home路由模式)。 因此,它会尝试将请求发送到操作方法,并且由于您在请求url中没有操作方法段,它将尝试使用在该路由注册中定义的默认值,即Index 。 您正在获取404,因为您的ProcessController没有Index操作方法。 如果将一个Index()操作方法添加到ProcessController ,它将执行该操作并从中返回结果 ...