2011-11-23 64 views
1

如何在ASP.NET Web服務中控制參數類型標記?我得到< xml>字符串</xml>在一個web應用程序和<數據>字符串< /數據>在其他...有沒有辦法控制這個?ASP.NET Web服務參數類型

[WebMethod] 
public bool TestFunction(string xml) 
{ 
    //DO SOMETHING 
    return true; 
} 

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
    <TestFunction xmlns="http://tempuri.org/"> 
     <xml>string</xml> //<data>string</data> 
    </TestFunction> 
    </soap:Body> 
</soap:Envelope> 

編輯:我忘了使用您指定的參數名稱重命名功能

回答

3

任何方法被暴露。如果將方法更改爲public bool TestFunction(string FooBar),則該字符串將位於生成的XML中的<FooBar>string</FooBar>標記中。

當您使用WCF您可以使用Message合同或應用MessageParameter指示串行使用備用名稱改變這種行爲:

public bool TestFunction([MessageParameter(Name="YourName")]string xml) 

不過,我不知道這是否也適用於ASP.Net網絡服務。

+0

是的,這是一個參數名稱,我認爲它與傳輸數據類型有關,因爲名稱。 – redman