How to provide a C# .Net Web Service without an ‘elementformdefault = “qualified”’ attribute in the WSDL?

被刻印的时光 ゝ 提交于 2019-12-13 09:50:28

问题


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.

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

I’ll receive something like

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

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>

or

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

The web service works fine.

Thanks for your support


回答1:


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.

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).

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

The way you do it is to add

[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****/
}


来源:https://stackoverflow.com/questions/29966255/how-to-provide-a-c-sharp-net-web-service-without-an-elementformdefault-qual

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!