我会假设你使用Json对象来请求数据。
它应该是这样的:
[OperationContract]
[WebInvoke(UriTemplate = "UpdateUserDetails?_clientIP={_clientIP}&AdminName={AdminName}", Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
public void UpdateUserDetails(UserConfigData _userConfigData, ConfigResult _configResult, string _clientIP, string AdminName)
和JSON数据似乎是这样的:
{
"_userConfigData":{
"Property1":"value",
"Property2":"value",
"Property3":"value"
..and so on...
},
"_configResult":{
"Property1":"value",
"Property2":"value",
"Property3":"value"
..and so on...
}
}
有用于测试REST服务良好的应用,你可以尝试使用:
Fiddler
附加信息
为响应结果“越来越未找到方法”
您可能没有正确定义端点或服务地址。你的webconfig文件应该有这种配置。
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
<bindings>
<basicHttpBinding>
<binding name="soapBinding">
<security mode="None"></security>
</binding>
</basicHttpBinding>
<webHttpBinding>
<binding name="webBinding"></binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="jsonBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="defaultServiceBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<!-- USING SOAP-->
<service behaviorConfiguration="defaultServiceBehavior" name="MyProject.WCF.UserConfig.UserConfigService">
<endpoint address="soap" binding="basicHttpBinding" bindingConfiguration="soapBinding" contract="MyProject.WCF.UserConfig.IUserConfigService"></endpoint>
</service>
<!-- USING JSON-->
<service behaviorConfiguration="defaultServiceBehavior" name="MyProject.WCF.UserConfig.UserConfigService">
<endpoint address="json" binding="webHttpBinding" bindingConfiguration="webBinding" behaviorConfiguration="jsonBehavior" contract="MyProject.WCF.UserConfig.IUserConfigService"></endpoint>
</service>
</services>
</system.serviceModel>
地址似乎是这样的:
SOAP
localhost:1706/soap/UserConfigService.svc
JSON
localhost:1706/json/UserConfigService.svc
为了更好的参考,你可以尝试看这里:
How to create simple REST Based WCF Service with JSON format
谢谢,我用POST试了一下。但是,当我尝试从浏览器访问方法如下所示,我得到方法未找到。有任何想法吗? http:// localhost:1706/WCF/UserConfig/UserConfigService.svc/UpdateUserDetails?configdata = test&configresult = test3 @&clientip = localhost – codematrix 2012-02-22 00:29:42
看到我的编辑..希望它可以帮助 – fiberOptics 2012-02-22 01:10:12