2013-07-09 115 views
1

是否可以配置WCF方法HelloWorld(string test){}以接受發佈的數據,而無需實際指定第一個參數的名稱?不命名參數調用WCF函數?

I.E.而不是

<s:Body...> 
    <HelloWorld...> 
    <test>foo</test> 
    </HelloWorld> 
</s:Body> 

發送

<s:Body...> 
    <HelloWorld...> 
    foo 
    </HelloWorld> 
</s:Body> 

我認爲它可以通過改變參數類型從StringStream,但我寧願不要去那裏。

+0

我認爲可以通過爲該方法定義URI模板HelloWorld(string test){} –

回答

0

我認爲這是可能的,下面是我所瞭解的解決方案。

WCF接口

[ServiceContract] 
public interface IService1 
{ 
    [OperationContract] 
    [WebGet(UriTemplate = "HelloWorld/{test}")] 
    string HelloWorld(string test); 
} 

WCF接口實現

public class Service : IService1 
{ 
    return "Success from Hello World"; 
} 

從阿賈克斯jQuery的

$.ajax({ 
     type: 'GET', 
     dataType: 'json', 
     contentType: 'application/json; charset=utf-8', 
     url: baseUrl + '/HelloWorld/TestString', 
     success: function (response) { 
       alert('Ping reply: ' + response); 
     }, 
     error: function (XMLHttpRequest, textStatus, errorThrown) { 
       var jsonFault = JSON.parse(XMLHttpRequest.responseText); 
       alert('Reason: ' + jsonFault.Reason + '<br />Detail: ' + jsonFault.DetailedInformation); 
     } 
}); 

呼叫我試着用單一的參數。如果我錯了,請更多地解釋我。

查詢歡迎...