如何在 WSDL 中提供没有“elementformdefault = “qualified""属性的 C# .Net Web 服务? [英] How to provide a C# .Net Web Service without an ‘elementformdefault = “qualified”’ attribute in the WSDL?

查看:48
本文介绍了如何在 WSDL 中提供没有“elementformdefault = “qualified""属性的 C# .Net Web 服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将为具有给定 WSDL 的客户端提供 Web 服务.不幸的是,我无法告诉序列化程序接受不合格的 elementForm.

I’ll provide a web service for a client with a given WSDL. Unfortunately I’m not able to tell the serializer to accept unqualified elementForm.

我正在寻找将 elementFormDefault 设置为不合格"或什至无"以将其隐藏完整的方法

I seek for the way to set the elementFormDefault to either "unqualified" or even "None" to hide it complete

我会收到类似的东西

<NS:Request>
    <some stuff>…</some stuff>
</NS:Request>

但我在我的请求中没有看到任何内容仅当我更改前缀或删除前缀并通过向请求添加新 NS 来更改 NS 范围时

But I see no content in my request Only if I Change the prefix or remove the prefix and change the NS scope by adding a new NS to the request

<NS:Request>
  < NS:some stuff>…</ NS:some stuff>
</NS:Request>

< Request xmlns:myNamespace>
   < some stuff>…</some stuff>
</Request>

网络服务工作正常.

感谢您的支持

推荐答案

虽然这是 2 年前的死问题,但我还是想回答一下,因为这是我遇到完全相同的问题时的第一个相关搜索结果.

Although this is a dead question from 2 years ago, I would still like to answer it as this is my first related search result when I encounter the exact same problem.

通过 .asmx?wsdl 生成的 WSDL 文件有一个属性

The WSDL file generated via .asmx?wsdl has an attribute

elementFormDefault=qualified

在它的模式标记中,如果客户端成功将输入传递给服务器,则强制客户端向所有输入元素添加命名空间前缀.(如果客户端忽略命名空间前缀,服务器将收到没有输入的空请求).

within it's schema tag, which forces the clients to add a namespace prefix to all input element if they were to successfully pass their input to server. (If the client ignore the namespace prefix regardless, the server will receive empty request with no input).

由于在我的情况下,我的客户端无论如何都无法生成合格的soap请求,因此我必须在服务器端进行更改.

Since in my case my client could not generate a qualified soap request no matter what, I have to change on server side.

你这样做的方法是添加

[XmlElement(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]

在每个网络方法的每个输入参数之前:

in front of every input parameter for every web method:

[WebMethod]
public string TestMethod(
    [XmlElement(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]string input1,
    [XmlElement(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]int input2)
{
    /***code here****/
}

这篇关于如何在 WSDL 中提供没有“elementformdefault = “qualified""属性的 C# .Net Web 服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆