2013-07-09 109 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); 
     } 
}); 

呼叫我试着用单一的参数。如果我错了,请更多地解释我。

查询欢迎...