我做了一些更改,现在得到 415 Unsupported Media Type。我正在发布更新的代码。我的 Web 服务接口。
服务/IWebService.cs
[OperationContract]
[WebInvoke(Method = "POST",
BodyStyle=WebMessageBodyStyle.Wrapped,
RequestFormat=WebMessageFormat.Json,
ResponseFormat=WebMessageFormat.Json,
UriTemplate = "http://localhost:50571/Service/WebService.svc/hello/say")]
string hello(Deneme deneme );
[DataContract]
public class Deneme
{
[DataMember]
public string say { get; set; }
}
我的网络服务。服务/WebService.svc
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class WebService : IWebService
{
public string hello(Deneme deneme) {
return deneme.say;
}
客户端代码。在登录.aspx
$.ajax({
type: 'POST',
url: '/Service/WebService.svc/hello',
data: { 'say': 'sdfs' },
contentType: 'application/json; charset=utf-8',
dataType:'json',
success: function (s) {
alert(s.d);
}
});
网页配置
<system.serviceModel>
<services>
<service name="TETP.Service.WebService">
<endpoint address=""
behaviorConfiguration=""
binding="basicHttpBinding"
contract="TETP.Service.IWebService" />
</service>
</services>
<behaviors>
<serviceBehaviors >
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" />
<client>
<endpoint address="http://localhost:50571/Service/WebService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IWebService" contract="TETP.Service.IWebService" name="BasicHttpBinding_IWebService" />
</client>
我曾经收到 400 错误请求错误。现在我收到 415 Unsupported Media Type 错误 提前谢谢你。