我已经创建了简单的web服务。代码:
[ServiceContract]
public interface ITsdxService
{
[OperationContract]
void DoWork();
[OperationContract]
string Test();
}
public class TsdxService : ITsdxService
{
public void DoWork()
{
}
public string Test()
{
return "Hello World!";
}
}Web.config:
<system.serviceModel>
<services>
<service name="Test.TSDX.UI.TsdxService">
<endpoint
address="Tsdx"
binding="wsHttpBinding"
bindingConfiguration="TestBinding"
contract="Test.TSDX.UI.ITsdxService" />
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="TestBinding" />
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>当我在Visual Studio中运行时,我输入了localhost:50517/TsdxService.svc?wsdl一切正常-我可以看到wsdl,但是当我输入localhost:50517/TsdxService.svc/Tsdx/Test or localhost:50517/TsdxService.svc/Tsdx/DoWork时,我什么也看不到。小提琴手告诉我我得到了400个错误。断点(在Test和DoWork方法上)不起作用。为什么?我做错了什么?
发布于 2012-06-20 16:24:24
将属性添加到服务操作中。
[WebGet]
public string Test()
{
...
}为此,您还需要将WebScriptEnablingBehavior添加到服务配置中。另外,使用webHttpBinding。这些都是允许服务作为AJAX服务工作所必需的。
定义:
<endpointBehaviors>
<behavior name="EndpointBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>参考资料:
<endpoint behaviorConfiguration="EndpointBehavior"
binding="webHttpBinding"
...
/> https://stackoverflow.com/questions/11115395
复制相似问题