Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
291 views
in Technique[技术] by (71.8m points)

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...